@@ -540,8 +540,56 @@ impl Type {
540
540
} else if let Some ( location) = location {
541
541
match location. kind ( ) {
542
542
CXCursor_ClassTemplatePartialSpecialization |
543
+ CXCursor_CXXBaseSpecifier |
543
544
CXCursor_ClassTemplate => {
544
- name = location. spelling ( ) ;
545
+ if location. kind ( ) == CXCursor_CXXBaseSpecifier {
546
+ // In the case we're parsing a base specifier
547
+ // inside an unexposed or invalid type, it means
548
+ // that we're parsing one of two things:
549
+ //
550
+ // * A template parameter.
551
+ // * A complex class that isn't exposed.
552
+ //
553
+ // This means, unfortunately, that there's no
554
+ // good way to differentiate between them.
555
+ //
556
+ // Probably we could try to look at the
557
+ // declaration and complicate more this logic,
558
+ // but we'll keep it simple... if it's a valid
559
+ // C++ identifier, we'll consider it as a
560
+ // template parameter.
561
+ //
562
+ // This is because:
563
+ //
564
+ // * We expect every other base that is a
565
+ // proper identifier (that is, a simple
566
+ // struct/union declaration), to be exposed,
567
+ // so this path can't be reached in that
568
+ // case.
569
+ //
570
+ // * Quite conveniently, complex base
571
+ // specifiers preserve their full names (that
572
+ // is: Foo<T> instead of Foo). We can take
573
+ // advantage of this.
574
+ //
575
+ // If we find some edge case where this doesn't
576
+ // work (which I guess is unlikely, see the
577
+ // different test cases[1][2][3][4]), we'd need
578
+ // to find more creative ways of differentiating
579
+ // these two cases.
580
+ //
581
+ // [1]: inherit_named.hpp
582
+ // [2]: forward-inherit-struct-with-fields.hpp
583
+ // [3]: forward-inherit-struct.hpp
584
+ // [4]: inherit-namespaced.hpp
585
+ if location. spelling ( )
586
+ . chars ( )
587
+ . all ( |c| c. is_alphanumeric ( ) || c == '_' ) {
588
+ return Err ( ParseError :: Recurse ) ;
589
+ }
590
+ } else {
591
+ name = location. spelling ( ) ;
592
+ }
545
593
let complex = CompInfo :: from_ty ( potential_id,
546
594
ty,
547
595
Some ( location) ,
0 commit comments