[AST] Fix printing tag decl groups in decl contexts
authorJoel E. Denny <jdenny.ornl@gmail.com>
Tue, 15 May 2018 00:44:14 +0000 (00:44 +0000)
committerJoel E. Denny <jdenny.ornl@gmail.com>
Tue, 15 May 2018 00:44:14 +0000 (00:44 +0000)
commitae7c9443559ac420a6f401b7a24eb2fcea8ba3e8
tree0d39e1c0e8dc0762c0855ef2b693cbe2d3db40ba
parent980d93d0e0940fedb50906f7f31564fe24d2bded
[AST] Fix printing tag decl groups in decl contexts

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.

Reviewed by: rsmith

Differential Revision: https://reviews.llvm.org/D45465

llvm-svn: 332314
clang/lib/AST/DeclPrinter.cpp
clang/test/Misc/ast-print-enum-decl.c
clang/test/Misc/ast-print-record-decl.c
clang/test/Sema/ast-print.c
clang/test/SemaCXX/ast-print.cpp