summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h9
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp7
2 files changed, 13 insertions, 3 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index a61358ea0e9..724d08c3d85 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2639,7 +2639,8 @@ AST_MATCHER_P(CXXRecordDecl, isDerivedFrom,
/// 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, isSameOrDerivedFrom,
/// \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, isDirectlyDerivedFrom,
/// 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);
}
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 0fedb0c8d60..cb5cf9ebf52 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -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));
OpenPOWER on IntegriCloud