What are canonical Types in Clang

When I parse this code with an AST parser:

struct _poire {
    int g;
    char rouge; // tomate is probably one of your classes so I just changed the type of the field.
};
typedef struct _poire kudamono;

I have a clang::TypedefDecl then I get the clang::QualType of the typedef with clang::TypedefDecl::getUnderlyingType()

With the QualType if I use the getAsString method I can find the “struct _poire” std::string. All this is Ok.

The problem is if I try to see if this type is a canonical type, with QualType::isCanonical(), it returns false.

So I try to get the canonical type with QualType::getCanonicalType().getAsString() and it returns the same string “struct _poire”.

according to the clang reference on type http://clang.llvm.org/docs/InternalsManual.html#canonical-types , I thought that the isCanonical() should return true when no typedef is involved.

So what are really canonical type?

(more informations on my problem can be seen here )

Cedlemo

When I parse this code with an AST parser:

struct _poire {
    int g;
    char rouge; // tomate is probably one of your classes so I just changed the type of the field.};typedef struct _poire kudamono;
I have a clang::TypedefDecl then I get the clang::QualType of the typedef with clang::TypedefDecl::getUnderlyingType()

With the QualType if I use the getAsString method I can find the "struct
_poire" std::string. All this is Ok.

The problem is if I try to see if this type is a canonical type, with
QualType::isCanonical(), it returns false.

So I try to get the canonical type with
QualType::getCanonicalType().getAsString() and it returns the same string
"struct _poire".

OK, but presumably it's a different QualType value, and this one's
isCanonical() will return true?

according to the clang reference on type
http://clang.llvm.org/docs/InternalsManual.html#canonical-types , I
thought that the isCanonical() should return true when no typedef is
involved.

No, there are lots of other things that can make a type non-canonical.

No, there are lots of other things that can make a type non-canonical.

Could you be a bit more specific ?

Cedlemo

Sure. Consider:

  int (x);

The type of x is not a BuiltinType; it's a ParenType whose canonical type
is a BuiltinType. And given

  struct X { int n; };
  struct X x;

the type of x will probably be represented as an ElaboratedType whose
canonical type is a RecordType.