]> granicus.if.org Git - clang/commitdiff
Fix pretty-printing for unnamed unions.
authorEli Friedman <eli.friedman@gmail.com>
Mon, 12 Aug 2013 21:54:04 +0000 (21:54 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 12 Aug 2013 21:54:04 +0000 (21:54 +0000)
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

lib/AST/DeclPrinter.cpp
lib/AST/TypePrinter.cpp
test/SemaCXX/ast-print.cpp

index 10ef28828c4502509d138b4c9e3f22e0934b3ae4..1e2d9d6e0846bd885a2eb3d82b6e27a387590983 100644 (file)
@@ -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<ElaboratedType>(BaseType))
+        BaseType = cast<ElaboratedType>(BaseType)->getNamedType();
       if (!BaseType.isNull() && isa<TagType>(BaseType) &&
           cast<TagType>(BaseType)->getDecl() == Decls[0]) {
         Decls.push_back(*D);
index 3b917aa33fb371f9a5f5daf363a804f7c592b3a8..f6fd886e8a46793380272ff5dfb0b29e07a2d7da 100644 (file)
@@ -1003,6 +1003,8 @@ void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T,
 
 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
                                         raw_ostream &OS) {
+  if (Policy.SuppressTag && isa<TagType>(T->getNamedType()))
+    return;
   OS << TypeWithKeyword::getKeywordName(T->getKeyword());
   if (T->getKeyword() != ETK_None)
     OS << " ";
index 8e945bde7d6f08b06ca5db2b8e8b600d4dd88536..a1975b4ac2644b9a0a0f9b2efe8cd00dc9f56b1f 100644 (file)
@@ -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; };
+}