From: Douglas Gregor Date: Tue, 18 Oct 2011 02:43:19 +0000 (+0000) Subject: When transforming the arguments for a C++ "new" expression, make sure X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e8ea0b2e163aa9681e2f14ad75ab4990a69d39b;p=clang When transforming the arguments for a C++ "new" expression, make sure to drop the implicitly-generated value initialization expression used for initializing scalars. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142330 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index bb49eee2f3..64315ea15d 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6927,9 +6927,14 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr *E) { PlacementArgs, &ArgumentChanged)) return ExprError(); - // transform the constructor arguments (if any). + // Transform the constructor arguments (if any). + // As an annoying corner case, we may have introduced an implicit value- + // initialization expression when allocating a new array, which we implicitly + // drop. It will be re-created during type checking. ASTOwningVector ConstructorArgs(SemaRef); - if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, + if (!(E->isArray() && E->getNumConstructorArgs() == 1 && + isa(E->getConstructorArgs()[0])) && + TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, ConstructorArgs, &ArgumentChanged)) return ExprError(); @@ -7028,13 +7033,9 @@ TreeTransform::TransformCXXNewExpr(CXXNewExpr *E) { AllocType, AllocTypeInfo, ArraySize.get(), - /*FIXME:*/E->hasInitializer() - ? E->getLocStart() - : SourceLocation(), + E->getConstructorLParen(), move_arg(ConstructorArgs), - /*FIXME:*/E->hasInitializer() - ? E->getLocEnd() - : SourceLocation()); + E->getConstructorRParen()); } template diff --git a/test/SemaTemplate/instantiate-expr-1.cpp b/test/SemaTemplate/instantiate-expr-1.cpp index 896437488d..08f5e9d9a7 100644 --- a/test/SemaTemplate/instantiate-expr-1.cpp +++ b/test/SemaTemplate/instantiate-expr-1.cpp @@ -167,8 +167,15 @@ namespace PR6424 { new X(); // expected-note{{instantiation of}} } }; - + template void Y2<3>::f(); + + template + void rdar10283928(int count) { + (void)new char[count](); + } + + template void rdar10283928(int); } namespace PR10864 {