[cfe-dev] Type of enum constants

Eli Friedman eli.friedman at gmail.com
Fri Feb 24 13:46:51 PST 2012


On Fri, Feb 24, 2012 at 1:23 PM, Phil King <phil_king at rocketmail.com> wrote:
> If I have:
>
> typedef enum { E } e_t;
>
> and then an expression:
>
> a = E;
>
> is it possible to get back to the typedef name from the DeclRefExpr node for 'E' ?
>
> EnumConstantDecl * EC = dyn_cast< EnumConstantDecl >( DeclRefExpr->getDecl() );
>
> QualType = AC->getASTContext().getEnumType( dyn_cast< EnumDecl >( EC->getDeclContext() ) );
>
> gets me to enum { E } e_t, but not the typedef itself.

Try TagDecl::getTypedefNameForAnonDecl .

-Eli



More information about the cfe-dev mailing list