aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2012-11-08 22:53:48 +0000
committerDavid Blaikie <dblaikie@gmail.com>2012-11-08 22:53:48 +0000
commitc2fc67e0cf7dd061fda1aa90d81668f3e070d4cb (patch)
treee73833b3195f9738b36fcc5c0f04a056659cf421
parent45a37da030be06bb7babf5e65a64d62cd0def7e6 (diff)
Fix a source range regression in C++ new expressions with call initializers.
Introduced in r167507, discovered in review by Abramo Bagnara. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167597 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ExprCXX.cpp8
-rw-r--r--unittests/AST/SourceLocationTest.cpp6
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index f60f195b36..55722a2a99 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -130,6 +130,14 @@ CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
SubExprs[i++] = placementArgs[j];
}
+
+ switch (getInitializationStyle()) {
+ case CallInit:
+ this->Range.setEnd(DirectInitRange.getEnd()); break;
+ case ListInit:
+ this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break;
+ default: break;
+ }
}
void CXXNewExpr::AllocateArgsArray(ASTContext &C, bool isArray,
diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp
index 953cb9e42c..dec833d15d 100644
--- a/unittests/AST/SourceLocationTest.cpp
+++ b/unittests/AST/SourceLocationTest.cpp
@@ -258,6 +258,12 @@ TEST(CXXNewExpr, ArrayRange) {
EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", newExpr()));
}
+TEST(CXXNewExpr, ParenRange) {
+ RangeVerifier<CXXNewExpr> Verifier;
+ Verifier.expectRange(1, 12, 1, 20);
+ EXPECT_TRUE(Verifier.match("void f() { new int(); }", newExpr()));
+}
+
TEST(MemberExpr, ImplicitMemberRange) {
RangeVerifier<MemberExpr> Verifier;
Verifier.expectRange(2, 30, 2, 30);