For example, given:
struct T1 { struct T2 *p0; };
-ast-print produced:
struct T1 { struct T2; struct T2 *p0; };
Compiling that produces a warning that the first struct T2 declaration
does not declare anything.
Details:
A tag decl group is one or more decls that share a type specifier that
is a tag decl (that is, a struct/union/class/enum decl). Within
functions, the parser builds such a tag decl group as part of a
DeclStmt. However, in decl contexts, such as file scope or a member
list, the parser does not group together the members of a tag decl
group. Previously, detection of tag decl groups during printing was
implemented but only if the tag decl was unnamed. Otherwise, as in
the above example, the members of the group did not print together and
so sometimes introduced warnings.
This patch extends detection of tag decl groups in decl contexts to
any tag decl that is recorded in the AST as not free-standing.
I would think the right thing to check here is that the ElaboratedType's OwnedTagDecl is Decls[0]. Currently, you also allow cases where it's merely a redeclaration of that same TagDecl, which will combine together declarations too often...