CXXBaseSpecifiers not returning same Type

In the code below I would expect the CXXRecordDecls for BaseClass1 to have the same Type as both base class specifiers.

When I use getTypeForDecl() on the CXXRecordDecls I get the same Type*. When I use getType().getTypePtr() on the two CXXBaseSpecifiers I get different a Type* for each one, neither of which is the same as the CXXRecordDecl’s Type*.

Namespace N {
class BaseClass1;
class N::BaseClass1 {
class DerivedClass1 : public N::BaseClass1 {
class DerivedClass2 : public ::N::BaseClass1 {

This seems to indicate to me that the declared/defined class is of a different type from the base specifiers, and the base specifiers differ in type from each other.

What am I doing wrong with this? I really just want to see if the CXXBaseSpecifier matches the CXXRecordDecl.

Clang has both sugared and concrete types. By default, getting the type of some AST node will give you information about the type as written. In this case, two different nested name specifiers were used, so there are two different types.

If you want to compare types for equivalence, use the canonical types, or simply use ASTContext::hasSameType(QualType, QualType).

If I use either of those methods, it will also match typedefs, right? How would I modify that so that it doesn’t match typedefs, but will match different nested name specifiers?

You can specifically check for ElaboratedType and call desugar or getNamedType on it to get the type without the qualifier and compare those.