[PATCH] D65279: [clang] Fail for empty names in is*DerivedFrom matchers.
Anton Bikineev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 07:50:33 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367022: [clang] Fail for empty names in is*DerivedFrom matchers. (authored by AntonBikineev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D65279?vs=211734&id=211753#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65279/new/
https://reviews.llvm.org/D65279
Files:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -566,6 +566,13 @@
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));
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -2639,7 +2639,8 @@
/// 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 @@
/// \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 @@
/// 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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65279.211753.patch
Type: text/x-patch
Size: 2146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190725/34ae018d/attachment.bin>
More information about the cfe-commits
mailing list