forked from OSchip/llvm-project
Fixed source range for functional cast and unresolved construct expr nodes.
Added testcases. llvm-svn: 185773
This commit is contained in:
parent
7a22921e5a
commit
8421a06314
|
@ -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;
|
||||
|
|
|
@ -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 <typename T>
|
||||
/// 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".
|
||||
|
|
|
@ -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 <typename NodeType>
|
||||
|
@ -85,6 +85,10 @@ testing::AssertionResult MatchVerifier<NodeType>::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";
|
||||
}
|
||||
|
|
|
@ -201,5 +201,26 @@ TEST(UnaryTransformTypeLoc, ParensRange) {
|
|||
loc(unaryTransformType())));
|
||||
}
|
||||
|
||||
TEST(CXXFunctionalCastExpr, SourceRange) {
|
||||
RangeVerifier<CXXFunctionalCastExpr> Verifier;
|
||||
Verifier.expectRange(2, 10, 2, 14);
|
||||
EXPECT_TRUE(Verifier.match(
|
||||
"int foo() {\n"
|
||||
" return int{};\n"
|
||||
"}",
|
||||
functionalCastExpr(), Lang_CXX11));
|
||||
}
|
||||
|
||||
TEST(CXXUnresolvedConstructExpr, SourceRange) {
|
||||
RangeVerifier<CXXUnresolvedConstructExpr> Verifier;
|
||||
Verifier.expectRange(3, 10, 3, 12);
|
||||
EXPECT_TRUE(Verifier.match(
|
||||
"template <typename U>\n"
|
||||
"U foo() {\n"
|
||||
" return U{};\n"
|
||||
"}",
|
||||
unresolvedConstructExpr(), Lang_CXX11));
|
||||
}
|
||||
|
||||
} // end namespace ast_matchers
|
||||
} // end namespace clang
|
||||
|
|
Loading…
Reference in New Issue