From: Benjamin Kramer Date: Mon, 25 Jan 2016 10:34:06 +0000 (+0000) Subject: Fix printing of types in initializers with suppressed tags. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f54710ee0367c783c8c10553cb9a5e2c9e39e60;p=clang Fix printing of types in initializers with suppressed tags. 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 --- diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 5c6002d55c..6a3e8e2ae1 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -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(Init)) Out << ")"; } diff --git a/test/Sema/ast-print.c b/test/Sema/ast-print.c index b4d76844fe..b0e421410b 100644 --- a/test/Sema/ast-print.c +++ b/test/Sema/ast-print.c @@ -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){}}; +}