r246844 - Fix the perentheses location when the constructor is called on a class that has a destructor

Olivier Goffart via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 4 03:17:11 PDT 2015


Author: ogoffart
Date: Fri Sep  4 05:17:10 2015
New Revision: 246844

URL: http://llvm.org/viewvc/llvm-project?rev=246844&view=rev
Log:
Fix the perentheses location when the constructor is called on a class that has a destructor

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

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=246844&r1=246843&r2=246844&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Fri Sep  4 05:17:10 2015
@@ -2483,8 +2483,11 @@ ExprResult Sema::BuildCXXFunctionalCastE
   Op.CheckCXXCStyleCast(/*FunctionalStyle=*/true, /*ListInit=*/false);
   if (Op.SrcExpr.isInvalid())
     return ExprError();
-  
-  if (CXXConstructExpr *ConstructExpr = dyn_cast<CXXConstructExpr>(Op.SrcExpr.get()))
+
+  auto *SubExpr = Op.SrcExpr.get();
+  if (auto *BindExpr = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
+    SubExpr = BindExpr->getSubExpr();
+  if (auto *ConstructExpr = dyn_cast<CXXConstructExpr>(SubExpr))
     ConstructExpr->setParenOrBraceRange(SourceRange(LPLoc, RPLoc));
 
   return Op.complete(CXXFunctionalCastExpr::Create(Context, Op.ResultType,

Modified: cfe/trunk/test/SemaCXX/sourceranges.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/sourceranges.cpp?rev=246844&r1=246843&r2=246844&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/sourceranges.cpp (original)
+++ cfe/trunk/test/SemaCXX/sourceranges.cpp Fri Sep  4 05:17:10 2015
@@ -7,7 +7,7 @@ class P {
 };
 
 namespace foo {
-class A { public: A() {} };
+class A { public: A(int = 0) {} };
 enum B {};
 typedef int C;
 }
@@ -37,3 +37,16 @@ void destruct(foo::A *a1, foo::A *a2, P<
   // CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:13> '<bound member function type>' ->~P
   p1->~P<int>();
 }
+
+struct D {
+  D(int);
+  ~D();
+};
+
+void construct() {
+  using namespace foo;
+  A a = A(12);
+  // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'class foo::A' 'void (int)'
+  D d = D(12);
+  // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'struct D' 'void (int)'
+}




More information about the cfe-commits mailing list