From: Enea Zaffanella Date: Sun, 7 Jul 2013 06:41:54 +0000 (+0000) Subject: Fixed source range for functional cast and unresolved construct expr nodes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd9cbd22b832ce65a085801259cf2d3df77830e4;p=clang Fixed source range for functional cast and unresolved construct expr nodes. Added testcases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185773 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 925b16697c..128664c97e 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1224,7 +1224,9 @@ public: void setRParenLoc(SourceLocation L) { RParenLoc = L; } SourceLocation getLocStart() const LLVM_READONLY { return TyBeginLoc; } - SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { + return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd(); + } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXFunctionalCastExprClass; @@ -3069,7 +3071,10 @@ public: } SourceLocation getLocStart() const LLVM_READONLY; - SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { + assert(RParenLoc.isValid() || NumArgs == 1); + return RParenLoc.isValid() ? RParenLoc : getArg(0)->getLocEnd(); + } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXUnresolvedConstructExprClass; diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 110638a278..aa2e4f7cb8 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -640,6 +640,18 @@ const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstructExpr> constructExpr; +/// \brief Matches unresolved constructor call expressions. +/// +/// Example matches T(t) in return statement of f +/// (matcher = unresolvedConstructExpr()) +/// \code +/// template +/// void f(const T& t) { return T(t); } +/// \endcode +const internal::VariadicDynCastAllOfMatcher< + Stmt, + CXXUnresolvedConstructExpr> unresolvedConstructExpr; + /// \brief Matches implicit and explicit this expressions. /// /// Example matches the implicit this expression in "return i". diff --git a/unittests/AST/MatchVerifier.h b/unittests/AST/MatchVerifier.h index 7aa78860aa..56dcc68f20 100644 --- a/unittests/AST/MatchVerifier.h +++ b/unittests/AST/MatchVerifier.h @@ -25,7 +25,7 @@ namespace clang { namespace ast_matchers { -enum Language { Lang_C, Lang_C89, Lang_CXX, Lang_OpenCL }; +enum Language { Lang_C, Lang_C89, Lang_CXX, Lang_CXX11, Lang_OpenCL }; /// \brief Base class for verifying some property of nodes found by a matcher. template @@ -85,6 +85,10 @@ testing::AssertionResult MatchVerifier::match( Args.push_back("-std=c++98"); FileName = "input.cc"; break; + case Lang_CXX11: + Args.push_back("-std=c++11"); + FileName = "input.cc"; + break; case Lang_OpenCL: FileName = "input.cl"; } diff --git a/unittests/AST/SourceLocationTest.cpp b/unittests/AST/SourceLocationTest.cpp index be63085b8a..697c6a04b7 100644 --- a/unittests/AST/SourceLocationTest.cpp +++ b/unittests/AST/SourceLocationTest.cpp @@ -201,5 +201,26 @@ TEST(UnaryTransformTypeLoc, ParensRange) { loc(unaryTransformType()))); } +TEST(CXXFunctionalCastExpr, SourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(2, 10, 2, 14); + EXPECT_TRUE(Verifier.match( + "int foo() {\n" + " return int{};\n" + "}", + functionalCastExpr(), Lang_CXX11)); +} + +TEST(CXXUnresolvedConstructExpr, SourceRange) { + RangeVerifier Verifier; + Verifier.expectRange(3, 10, 3, 12); + EXPECT_TRUE(Verifier.match( + "template \n" + "U foo() {\n" + " return U{};\n" + "}", + unresolvedConstructExpr(), Lang_CXX11)); +} + } // end namespace ast_matchers } // end namespace clang