From: Eli Friedman Date: Mon, 17 Jun 2013 22:35:10 +0000 (+0000) Subject: Fix source range of CXXNewExpr with parentheses around the type. PR15569. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e40c9544a0215c3e632e1fb79d5161adc464101;p=clang Fix source range of CXXNewExpr with parentheses around the type. PR15569. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184139 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 59e780ae0a..55bd1990f6 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -134,7 +134,10 @@ CXXNewExpr::CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew, this->Range.setEnd(DirectInitRange.getEnd()); break; case ListInit: this->Range.setEnd(getInitializer()->getSourceRange().getEnd()); break; - default: break; + default: + if (TypeIdParens.isValid()) + this->Range.setEnd(TypeIdParens.getEnd()); + break; } } diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index 990e6dfc85..669fcd48a4 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -174,5 +174,11 @@ TEST(TemplateSpecializationTypeLoc, AngleBracketLocations) { loc(templateSpecializationType()))); } +TEST(CXXNewExpr, TypeParenRange) { + RangeVerifier Verifier; + Verifier.expectRange(1, 10, 1, 18); + EXPECT_TRUE(Verifier.match("int* a = new (int);", newExpr())); +} + } // end namespace ast_matchers } // end namespace clang