From: Douglas Gregor Date: Mon, 27 Jun 2011 16:55:54 +0000 (+0000) Subject: When instantiating a C++ "new" expression, don't fake source locations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0e8b782787638bcc9c57022e47c28d3529f02d4;p=clang When instantiating a C++ "new" expression, don't fake source locations 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 --- diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 0d923d113a..edbf1fb459 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6937,9 +6937,13 @@ TreeTransform::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 diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp index d14a5e251c..bd307f1086 100644 --- a/test/CodeGenCXX/new.cpp +++ b/test/CodeGenCXX/new.cpp @@ -209,3 +209,16 @@ namespace test15 { new (p) A[n]; } } + +namespace PR10197 { + // CHECK: define weak_odr void @_ZN7PR101971fIiEEvv() + template + void f() { + // CHECK: [[CALL:%.*]] = call noalias i8* @_Znwm + // CHECK-NEXT: [[CASTED:%.*]] = bitcast i8* [[CALL]] to + new T; + // CHECK-NEXT: ret void + } + + template void f(); +}