]> granicus.if.org Git - clang/commitdiff
Fix printing of types in initializers with suppressed tags.
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 25 Jan 2016 10:34:06 +0000 (10:34 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 25 Jan 2016 10:34:06 +0000 (10:34 +0000)
Tag and specifier printing can be suppressed in Decl::printGroup, but these suppressions leak into the initializers. Thus
    int *x = ((void *)0), *y = ((void *)0);
gets printed as
    int *x = ((void *)0), *y = ((*)0);
And
    struct { struct Z z; } z = {(struct Z){}};
gets printed as
    struct { struct Z z; } z = {(){}};
The stops the suppressions from leaking into the initializers.

Patch by Nick Sumner!

Differential Revision: http://reviews.llvm.org/D16438

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258679 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclPrinter.cpp
test/Sema/ast-print.c

index 5c6002d55c0f8db1c2d195d0919b5c50961dbc72..6a3e8e2ae1a016110162576a89340df872422ac3 100644 (file)
@@ -751,7 +751,10 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
       else if (D->getInitStyle() == VarDecl::CInit) {
         Out << " = ";
       }
-      Init->printPretty(Out, nullptr, Policy, Indentation);
+      PrintingPolicy SubPolicy(Policy);
+      SubPolicy.SuppressSpecifiers = false;
+      SubPolicy.SuppressTag = false;
+      Init->printPretty(Out, nullptr, SubPolicy, Indentation);
       if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
         Out << ")";
     }
index b4d76844fef780812aa45291135fb7b9f6cc721b..b0e421410b24b87b5fbb55ab9b51428d54a68979 100644 (file)
@@ -53,3 +53,13 @@ struct pair_t {
 
 // CHECK: struct pair_t p = {a: 3, .b = 4};
 struct pair_t p = {a: 3, .b = 4};
+
+void initializers() {
+  // CHECK: int *x = ((void *)0), *y = ((void *)0);
+  int *x = ((void *)0), *y = ((void *)0);
+  struct Z{};
+  struct {
+    struct Z z;
+  // CHECK: } z = {(struct Z){}};
+  } z = {(struct Z){}};
+}