From: Eli Friedman Date: Mon, 12 Aug 2013 21:54:04 +0000 (+0000) Subject: Fix pretty-printing for unnamed unions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=42acc0c357557574514814863cab950f23cbff5e;p=clang Fix pretty-printing for unnamed unions. This is just a couple of minor fixes to account for the existence of ElaboratedType. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188209 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 10ef28828c..1e2d9d6e08 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -260,6 +260,8 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { QualType CurDeclType = getDeclType(*D); if (!Decls.empty() && !CurDeclType.isNull()) { QualType BaseType = GetBaseType(CurDeclType); + if (!BaseType.isNull() && isa(BaseType)) + BaseType = cast(BaseType)->getNamedType(); if (!BaseType.isNull() && isa(BaseType) && cast(BaseType)->getDecl() == Decls[0]) { Decls.push_back(*D); diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 3b917aa33f..f6fd886e8a 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -1003,6 +1003,8 @@ void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T, void TypePrinter::printElaboratedBefore(const ElaboratedType *T, raw_ostream &OS) { + if (Policy.SuppressTag && isa(T->getNamedType())) + return; OS << TypeWithKeyword::getKeywordName(T->getKeyword()); if (T->getKeyword() != ETK_None) OS << " "; diff --git a/test/SemaCXX/ast-print.cpp b/test/SemaCXX/ast-print.cpp index 8e945bde7d..a1975b4ac2 100644 --- a/test/SemaCXX/ast-print.cpp +++ b/test/SemaCXX/ast-print.cpp @@ -153,3 +153,14 @@ void test13() { __c11_atomic_load(&i, 0); } + +// CHECK: void test14() { +// CHECK: struct X { +// CHECK: union { +// CHECK: int x; +// CHECK: } x; +// CHECK: }; +// CHECK: } +void test14() { + struct X { union { int x; } x; }; +}