[cfe-commits] r142330 - in /cfe/trunk: lib/Sema/TreeTransform.h test/SemaTemplate/instantiate-expr-1.cpp

Douglas Gregor dgregor at apple.com
Mon Oct 17 19:43:19 PDT 2011


Author: dgregor
Date: Mon Oct 17 21:43:19 2011
New Revision: 142330

URL: http://llvm.org/viewvc/llvm-project?rev=142330&view=rev
Log:
When transforming the arguments for a C++ "new" expression, make sure
to drop the implicitly-generated value initialization expression used
for initializing scalars. Fixes <rdar://problem/10283928>.

Modified:
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/SemaTemplate/instantiate-expr-1.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=142330&r1=142329&r2=142330&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Oct 17 21:43:19 2011
@@ -6927,9 +6927,14 @@
                                   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 @@
                                         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>

Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-1.cpp?rev=142330&r1=142329&r2=142330&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-1.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-1.cpp Mon Oct 17 21:43:19 2011
@@ -167,8 +167,15 @@
       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 {





More information about the cfe-commits mailing list