зеркало из https://github.com/microsoft/clang-1.git
New matcher for MaterializeTemporaryExpr
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162609 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
56d7f2348a
Коммит
e16acd3817
|
@ -552,6 +552,28 @@ const internal::VariadicDynCastAllOfMatcher<
|
|||
Stmt,
|
||||
CXXBindTemporaryExpr> bindTemporaryExpr;
|
||||
|
||||
/// \brief Matches nodes where temporaries are materialized.
|
||||
///
|
||||
/// Example: Given
|
||||
/// \code
|
||||
/// struct T {void func()};
|
||||
/// T f();
|
||||
/// void g(T);
|
||||
/// \endcode
|
||||
/// materializeTemporaryExpr() matches 'f()' in these statements
|
||||
/// \code
|
||||
/// T u(f());
|
||||
/// g(f());
|
||||
/// \endcode
|
||||
/// but does not match
|
||||
/// \code
|
||||
/// f();
|
||||
/// f().func();
|
||||
/// \endcode
|
||||
const internal::VariadicDynCastAllOfMatcher<
|
||||
Stmt,
|
||||
MaterializeTemporaryExpr> materializeTemporaryExpr;
|
||||
|
||||
/// \brief Matches new expressions.
|
||||
///
|
||||
/// Given
|
||||
|
|
|
@ -1296,6 +1296,41 @@ TEST(Matcher, BindTemporaryExpression) {
|
|||
TempExpression));
|
||||
}
|
||||
|
||||
TEST(MaterializeTemporaryExpr, MatchesTemporary) {
|
||||
std::string ClassString =
|
||||
"class string { public: string(); int length(); }; ";
|
||||
|
||||
EXPECT_TRUE(
|
||||
matches(ClassString +
|
||||
"string GetStringByValue();"
|
||||
"void FunctionTakesString(string s);"
|
||||
"void run() { FunctionTakesString(GetStringByValue()); }",
|
||||
materializeTemporaryExpr()));
|
||||
|
||||
EXPECT_TRUE(
|
||||
notMatches(ClassString +
|
||||
"string* GetStringPointer(); "
|
||||
"void FunctionTakesStringPtr(string* s);"
|
||||
"void run() {"
|
||||
" string* s = GetStringPointer();"
|
||||
" FunctionTakesStringPtr(GetStringPointer());"
|
||||
" FunctionTakesStringPtr(s);"
|
||||
"}",
|
||||
materializeTemporaryExpr()));
|
||||
|
||||
EXPECT_TRUE(
|
||||
notMatches(ClassString +
|
||||
"string GetStringByValue();"
|
||||
"void run() { int k = GetStringByValue().length(); }",
|
||||
materializeTemporaryExpr()));
|
||||
|
||||
EXPECT_TRUE(
|
||||
notMatches(ClassString +
|
||||
"string GetStringByValue();"
|
||||
"void run() { GetStringByValue(); }",
|
||||
materializeTemporaryExpr()));
|
||||
}
|
||||
|
||||
TEST(ConstructorDeclaration, SimpleCase) {
|
||||
EXPECT_TRUE(matches("class Foo { Foo(int i); };",
|
||||
constructorDecl(ofClass(hasName("Foo")))));
|
||||
|
|
Загрузка…
Ссылка в новой задаче