From: Aaron Ballman Date: Thu, 2 Jul 2015 14:02:41 +0000 (+0000) Subject: When testing for anyOf(), the test should not be for an exact type match for all... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=67f1fc17581bbab997d728668d26f01399cc01eb;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241263 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ASTMatchers/ASTMatchersInternal.cpp b/lib/ASTMatchers/ASTMatchersInternal.cpp index 2c482e38dc..b6ef8226a9 100644 --- a/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -114,9 +114,9 @@ DynTypedMatcher DynTypedMatcher::constructVariadic( 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. diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 1fc7979bd0..8ef3f15e4c 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -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) {