r241263 - When testing for anyOf(), the test should not be for an exact type match for all members of the set. Instead, test that all members are convertible to the common type.

Aaron Ballman aaron at aaronballman.com
Thu Jul 2 07:02:41 PDT 2015


Author: aaronballman
Date: Thu Jul  2 09:02:41 2015
New Revision: 241263

URL: http://llvm.org/viewvc/llvm-project?rev=241263&view=rev
Log:
When testing for anyOf(), the test should not be for an exact type match for all members of the set. Instead, test that all members are convertible to the common type.

Modified:
    cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
    cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=241263&r1=241262&r2=241263&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Thu Jul  2 09:02:41 2015
@@ -114,9 +114,9 @@ DynTypedMatcher DynTypedMatcher::constru
   assert(InnerMatchers.size() > 0 && "Array must not be empty.");
   assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(),
                      [&InnerMatchers](const DynTypedMatcher &M) {
-           return InnerMatchers[0].SupportedKind.isSame(M.SupportedKind);
+           return InnerMatchers[0].canConvertTo(M.SupportedKind);
          }) &&
-         "SupportedKind must match!");
+         "SupportedKind must be convertible to a common type!");
 
   auto SupportedKind = InnerMatchers[0].SupportedKind;
   // We must relax the restrict kind here.

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=241263&r1=241262&r2=241263&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Thu Jul  2 09:02:41 2015
@@ -482,6 +482,10 @@ TEST(DeclarationMatcher, MatchAnyOf) {
   EXPECT_TRUE(matches("int F() { return 1 + 2; }", MixedTypes));
   EXPECT_TRUE(matches("int F() { if (true) return 1; }", MixedTypes));
   EXPECT_TRUE(notMatches("int F() { return 1; }", MixedTypes));
+
+  EXPECT_TRUE(
+      matches("void f() try { } catch (int) { } catch (...) { }",
+              catchStmt(anyOf(hasDescendant(varDecl()), isCatchAll()))));
 }
 
 TEST(DeclarationMatcher, MatchHas) {





More information about the cfe-commits mailing list