From a117002d93b1f0e9488a68d5d3b540ca795bc9e5 Mon Sep 17 00:00:00 2001 From: Samuel Benzaquen Date: Mon, 6 Oct 2014 13:14:30 +0000 Subject: Fix bug in DynTypedMatcher::constructVariadic() that would cause false negatives. Summary: DynTypedMatcher::constructVariadic() where the restrict kind of the different matchers are not related causes the matcher to have a "None" restrict kind. This causes false negatives for anyOf and eachOf. Change the logic to get a common ancestor if there is one. Also added regression tests that fail without the fix. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D5580 llvm-svn: 219118 --- clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.cpp') diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 4eb4c0d6727..a7969340ba8 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -460,6 +460,11 @@ TEST(DeclarationMatcher, MatchAnyOf) { EXPECT_TRUE(matches("class U {};", XOrYOrZOrUOrV)); EXPECT_TRUE(matches("class V {};", XOrYOrZOrUOrV)); EXPECT_TRUE(notMatches("class A {};", XOrYOrZOrUOrV)); + + StatementMatcher MixedTypes = stmt(anyOf(ifStmt(), binaryOperator())); + 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)); } TEST(DeclarationMatcher, MatchHas) { -- cgit v1.2.3