]> granicus.if.org Git - clang/commitdiff
When transforming the arguments for a C++ "new" expression, make sure
authorDouglas Gregor <dgregor@apple.com>
Tue, 18 Oct 2011 02:43:19 +0000 (02:43 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 18 Oct 2011 02:43:19 +0000 (02:43 +0000)
to drop the implicitly-generated value initialization expression used
for initializing scalars. Fixes <rdar://problem/10283928>.

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

lib/Sema/TreeTransform.h
test/SemaTemplate/instantiate-expr-1.cpp

index bb49eee2f332c1c5fd1e4f6738f24bfd04d65ba0..64315ea15d0dc5ed8be71e21cf114179ad86414e 100644 (file)
@@ -6927,9 +6927,14 @@ TreeTransform<Derived>::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<Expr*> ConstructorArgs(SemaRef);
-  if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
+  if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
+        isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
+      TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
                      ConstructorArgs, &ArgumentChanged))
     return ExprError();  
 
@@ -7028,13 +7033,9 @@ TreeTransform<Derived>::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<typename Derived>
index 896437488d68a884aeb32960c2cd1215243f7716..08f5e9d9a7f0bb260e8fe457e08dfba3b6138edd 100644 (file)
@@ -167,8 +167,15 @@ namespace PR6424 {
       new X(); // expected-note{{instantiation of}}
     }
   };
-
+  
   template void Y2<3>::f();
+
+  template<typename T>
+  void rdar10283928(int count) {
+    (void)new char[count]();
+  }
+
+  template void rdar10283928<int>(int);
 }
 
 namespace PR10864 {