From: Eli Friedman Date: Thu, 18 Oct 2012 20:54:37 +0000 (+0000) Subject: Fix AST pretty-printing for C++ new expressions with placement arguments with default... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d03ef04ed32e9c9d7c714e8f1b31693c5b907dd2;p=clang Fix AST pretty-printing for C++ new expressions with placement arguments with default values. Based on patch by Grzegorz Jablonski. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166226 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 892442ea3b..d7392af808 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1415,10 +1415,12 @@ void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) { OS << "::"; OS << "new "; unsigned NumPlace = E->getNumPlacementArgs(); - if (NumPlace > 0) { + if (NumPlace > 0 && !isa(E->getPlacementArg(0))) { OS << "("; PrintExpr(E->getPlacementArg(0)); for (unsigned i = 1; i < NumPlace; ++i) { + if (isa(E->getPlacementArg(i))) + break; OS << ", "; PrintExpr(E->getPlacementArg(i)); } diff --git a/test/SemaCXX/ast-print.cpp b/test/SemaCXX/ast-print.cpp index 44b34aa12c..46b99e0d61 100644 --- a/test/SemaCXX/ast-print.cpp +++ b/test/SemaCXX/ast-print.cpp @@ -30,3 +30,14 @@ void f() switch (int a = 1) { } } +// CHECK: new (1) int; +void *operator new (typeof(sizeof(1)), int, int = 2); +void f2() { + new (1) int; +} + +// CHECK: new X; +struct X { + void *operator new (typeof(sizeof(1)), int = 2); +}; +void f2() { new X; }