[cfe-dev] Patch adding a Boolean flag to TagDecl nodes.

Abramo Bagnara abramo.bagnara at gmail.com
Wed Feb 3 14:01:41 PST 2010

Il 03/02/2010 21:42, Douglas Gregor ha scritto:
> On Jan 29, 2010, at 12:10 PM, Enea Zaffanella wrote:
>> Hello.
>> The attached patch adds a new Boolean flag to TagDecl nodes.
>> The new flag, named IsDefinedInDeclarator, tells whether or not the
>> TagDecl is a definition that was syntactically occurring (possibly via
>> macro expansions) in a declarator. Examples include tag types defined in
>> function return types, function parameter types, variable or field
>> declarations and type arguments of cast or sizeof expressions.
>> The new flag is meant to help clients such as code style checkers.
> This feels like the wrong solution. I'd like to hear from others, but
> the best approach seems to be to extend TagTypeLoc with a bit that
> indicates whether this use of the tag type was a reference or a
> definition. That way, a pretty-printer could know exactly where to
> put the definition.

Our aim is exactly that and it works perfectly using the proposed patch:
the RecordDecl inserted in DeclContext parsing

typedef struct s { int a; } x;

is marked with IsDefinedInDeclarator bit and then can be excluded from
pretty printer output. Next, analyzing TypedefDecl it could be easily
verified that the location of TypedefDecl is the same of RecordDecl and
then we can know easily that the record definition was embedded in the
typedef declaration.


struct s { int a; };
typedef struct s x;

the RecordDecl is not marked and then the two declaration should not be

Following your proposal instead we have no way to understand that the
RecordDecl in the former case should not be output (RecordDecl does not
have TypeLoc where to store this info).

Take also in account that the bit you propose to add to typeloc is
already deducible now using the location trick above.

More information about the cfe-dev mailing list