[cfe-dev] typedef, TagType & isDefinition() bug.
Douglas Gregor
dgregor at apple.com
Tue Dec 23 13:43:56 PST 2008
On Dec 23, 2008, at 9:33 PM, Paolo Bolzoni wrote:
> Code example:
> ---->
> struct A;
> typedef struct A B;
> struct A { int a; };
> ----<
>
> The second declaration is of type clang::TypeDecl,
> using getUnderlyingType() I obtain the clang::QualType of the struct
> A.
>
> getTypePtr() gives me the clang::RecordType.
>
> But to know the name of the referenced struct (the `A') I need to use
> getDecl().
>
> getDecl() returns a pointer to the declaration, but this
> clang::RecordDecl's
> isDefinition() member function returns true. I think this is a bug.
RecordType::getDecl() always points at the definition (once we have a
definition) so that we can efficiently get from a type to its
definition. This is a relatively important ability, since many
operations involve looking into the definition of a class type.
>
> If not, how can I distinguish from this:
> ---->
> struct A;
> typedef struct A B;
> struct A { int a; };
> ----<
>
> to this?
> ---->
> struct A;
> typedef struct A { int a; } B;
> ----<
Right now, you can't. The work on DeclGroups---which is only partially
complete in Clang---is meant to represent the second case. It
currently deals with cases like, e.g.,
int x, y; // both x and y are in the same DeclGroup
but doesn't deal with tag types like structs.
- Doug
More information about the cfe-dev
mailing list