Skip to content

Commit 1ba7dc3

Browse files
committed
Fix the perentheses location when the constructor is called on a class that has a destructor
llvm-svn: 246844
1 parent a04668f commit 1ba7dc3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

clang/lib/Sema/SemaCast.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,8 +2483,11 @@ ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo,
24832483
Op.CheckCXXCStyleCast(/*FunctionalStyle=*/true, /*ListInit=*/false);
24842484
if (Op.SrcExpr.isInvalid())
24852485
return ExprError();
2486-
2487-
if (CXXConstructExpr *ConstructExpr = dyn_cast<CXXConstructExpr>(Op.SrcExpr.get()))
2486+
2487+
auto *SubExpr = Op.SrcExpr.get();
2488+
if (auto *BindExpr = dyn_cast<CXXBindTemporaryExpr>(SubExpr))
2489+
SubExpr = BindExpr->getSubExpr();
2490+
if (auto *ConstructExpr = dyn_cast<CXXConstructExpr>(SubExpr))
24882491
ConstructExpr->setParenOrBraceRange(SourceRange(LPLoc, RPLoc));
24892492

24902493
return Op.complete(CXXFunctionalCastExpr::Create(Context, Op.ResultType,

clang/test/SemaCXX/sourceranges.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class P {
77
};
88

99
namespace foo {
10-
class A { public: A() {} };
10+
class A { public: A(int = 0) {} };
1111
enum B {};
1212
typedef int C;
1313
}
@@ -37,3 +37,16 @@ void destruct(foo::A *a1, foo::A *a2, P<int> *p1) {
3737
// CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:13> '<bound member function type>' ->~P
3838
p1->~P<int>();
3939
}
40+
41+
struct D {
42+
D(int);
43+
~D();
44+
};
45+
46+
void construct() {
47+
using namespace foo;
48+
A a = A(12);
49+
// CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'class foo::A' 'void (int)'
50+
D d = D(12);
51+
// CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'struct D' 'void (int)'
52+
}

0 commit comments

Comments
 (0)