]> granicus.if.org Git - clang/commitdiff
When instantiating a C++ "new" expression, don't fake source locations
authorDouglas Gregor <dgregor@apple.com>
Mon, 27 Jun 2011 16:55:54 +0000 (16:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 27 Jun 2011 16:55:54 +0000 (16:55 +0000)
for the '(' and ')' around the initializer unless we actually have an
initializer. Fixes PR10197, an issue where we were value-initializing
rather than default-initializing.

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

lib/Sema/TreeTransform.h
test/CodeGenCXX/new.cpp

index 0d923d113a22214d6bbbd956dea837f36d78f89f..edbf1fb45900f72621ab17e383eb28f0fe8e74e4 100644 (file)
@@ -6937,9 +6937,13 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
                                         AllocType,
                                         AllocTypeInfo,
                                         ArraySize.get(),
-                                        /*FIXME:*/E->getLocStart(),
+                                        /*FIXME:*/E->hasInitializer()
+                                          ? E->getLocStart()
+                                          : SourceLocation(),
                                         move_arg(ConstructorArgs),
-                                        E->getLocEnd());
+                                        /*FIXME:*/E->hasInitializer()
+                                          ? E->getLocEnd()
+                                          : SourceLocation());
 }
 
 template<typename Derived>
index d14a5e251ce0c3443921947c5ae6fef2cba74866..bd307f10867d5039b557021186f89185362ae4b0 100644 (file)
@@ -209,3 +209,16 @@ namespace test15 {
     new (p) A[n];
   }
 }
+
+namespace PR10197 {
+  // CHECK: define weak_odr void @_ZN7PR101971fIiEEvv()
+  template<typename T>
+  void f() {
+    // CHECK: [[CALL:%.*]] = call noalias i8* @_Znwm
+    // CHECK-NEXT: [[CASTED:%.*]] = bitcast i8* [[CALL]] to 
+    new T;
+    // CHECK-NEXT: ret void
+  }
+
+  template void f<int>();
+}