r347261 - [Sema] Fix PR38987: keep end location of a direct initializer list

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 19 12:10:22 PST 2018


Author: vedantk
Date: Mon Nov 19 12:10:21 2018
New Revision: 347261

URL: http://llvm.org/viewvc/llvm-project?rev=347261&view=rev
Log:
[Sema] Fix PR38987: keep end location of a direct initializer list

If PerformConstructorInitialization of a direct initializer list constructor is
called while instantiating a template, it has brace locations in its BraceLoc
arguments but not in the Kind argument.

This reverts the hunk https://reviews.llvm.org/D41921#inline-468844.

Patch by Orivej Desh!

Differential Revision: https://reviews.llvm.org/D53231

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/sourceranges.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=347261&r1=347260&r2=347261&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Nov 19 12:10:21 2018
@@ -6186,7 +6186,10 @@ PerformConstructorInitialization(Sema &S
     TypeSourceInfo *TSInfo = Entity.getTypeSourceInfo();
     if (!TSInfo)
       TSInfo = S.Context.getTrivialTypeSourceInfo(Entity.getType(), Loc);
-    SourceRange ParenOrBraceRange = Kind.getParenOrBraceRange();
+    SourceRange ParenOrBraceRange =
+        (Kind.getKind() == InitializationKind::IK_DirectList)
+        ? SourceRange(LBraceLoc, RBraceLoc)
+        : Kind.getParenOrBraceRange();
 
     if (auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(
             Step.Function.FoundDecl.getDecl())) {

Modified: cfe/trunk/test/SemaCXX/sourceranges.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/sourceranges.cpp?rev=347261&r1=347260&r2=347261&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/sourceranges.cpp (original)
+++ cfe/trunk/test/SemaCXX/sourceranges.cpp Mon Nov 19 12:10:21 2018
@@ -52,6 +52,13 @@ void construct() {
   // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'D' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
 }
 
+namespace PR38987 {
+struct A { A(); };
+template <class T> void f() { T{}; }
+template void f<A>();
+// CHECK: CXXTemporaryObjectExpr {{.*}} <col:31, col:33> 'PR38987::A':'PR38987::A'
+}
+
 void abort() __attribute__((noreturn));
 
 namespace std {




More information about the cfe-commits mailing list