r367022 - [clang] Fail for empty names in is*DerivedFrom matchers.
Anton Bikineev via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 07:48:55 PDT 2019
Author: antonbikineev
Date: Thu Jul 25 07:48:55 2019
New Revision: 367022
URL: http://llvm.org/viewvc/llvm-project?rev=367022&view=rev
Log:
[clang] Fail for empty names in is*DerivedFrom matchers.
Differential Revision: https://reviews.llvm.org/D65279
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=367022&r1=367021&r2=367022&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Jul 25 07:48:55 2019
@@ -2639,7 +2639,8 @@ AST_MATCHER_P(CXXRecordDecl, isDerivedFr
/// Overloaded method as shortcut for \c isDerivedFrom(hasName(...)).
AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDerivedFrom, std::string, BaseName, 1) {
- assert(!BaseName.empty());
+ if (BaseName.empty())
+ return false;
return isDerivedFrom(hasName(BaseName)).matches(Node, Finder, Builder);
}
@@ -2655,7 +2656,8 @@ AST_MATCHER_P_OVERLOAD(CXXRecordDecl, is
/// \c isSameOrDerivedFrom(hasName(...)).
AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isSameOrDerivedFrom, std::string,
BaseName, 1) {
- assert(!BaseName.empty());
+ if (BaseName.empty())
+ return false;
return isSameOrDerivedFrom(hasName(BaseName)).matches(Node, Finder, Builder);
}
@@ -2687,7 +2689,8 @@ AST_MATCHER_P_OVERLOAD(CXXRecordDecl, is
/// Overloaded method as shortcut for \c isDirectlyDerivedFrom(hasName(...)).
AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDirectlyDerivedFrom, std::string,
BaseName, 1) {
- assert(!BaseName.empty());
+ if (BaseName.empty())
+ return false;
return isDirectlyDerivedFrom(hasName(BaseName))
.matches(Node, Finder, Builder);
}
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=367022&r1=367021&r2=367022&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Thu Jul 25 07:48:55 2019
@@ -566,6 +566,13 @@ TEST(DeclarationMatcher, ClassIsDerived)
cxxRecordDecl(isDerivedFrom(namedDecl(hasName("X"))))));
}
+TEST(DeclarationMatcher, IsDerivedFromEmptyName) {
+ const char *const Code = "class X {}; class Y : public X {};";
+ EXPECT_TRUE(notMatches(Code, cxxRecordDecl(isDerivedFrom(""))));
+ EXPECT_TRUE(notMatches(Code, cxxRecordDecl(isDirectlyDerivedFrom(""))));
+ EXPECT_TRUE(notMatches(Code, cxxRecordDecl(isSameOrDerivedFrom(""))));
+}
+
TEST(DeclarationMatcher, IsLambda) {
const auto IsLambda = cxxMethodDecl(ofClass(cxxRecordDecl(isLambda())));
EXPECT_TRUE(matches("auto x = []{};", IsLambda));
More information about the cfe-commits
mailing list