Matchers are registered to the pool each time one matcher rule is applied, but never removed from the collection. This means, for a project with multiple files, when matcher rule is applied to the N-th file, same matchers are added to the pool N times. This results in duplicated violations.
diff --git a/oclint-rules/include/oclint/AbstractASTMatcherRule.h b/oclint-rules/include/oclint/AbstractASTMatcherRule.h
index 7985345..83541a5 100644
--- a/oclint-rules/include/oclint/AbstractASTMatcherRule.h
+++ b/oclint-rules/include/oclint/AbstractASTMatcherRule.h
@@ -14,7 +14,7 @@ class AbstractASTMatcherRule :
public clang::ast_matchers::MatchFinder::MatchCallback
{
private:
- clang::ast_matchers::MatchFinder _finder;
+ clang::ast_matchers::MatchFinder *_finder;
protected:
virtual void run(const clang::ast_matchers::MatchFinder::MatchResult &result)
@@ -25,27 +25,34 @@ protected:
template<typename T>
void addMatcher(const T &nodeMatch)
{
- _finder.addMatcher(nodeMatch, this);
+ _finder->addMatcher(nodeMatch, this);
}
public:
virtual void setUp()
{
+ _finder = new clang::ast_matchers::MatchFinder();
setUpMatcher();
}
bool VisitDecl(clang::Decl *decl)
{
- _finder.match(*decl, *_carrier->getASTContext());
+ _finder->match(*decl, *_carrier->getASTContext());
return true;
}
bool VisitStmt(clang::Stmt *stmt)
{
- _finder.match(*stmt, *_carrier->getASTContext());
+ _finder->match(*stmt, *_carrier->getASTContext());
return true;
}
+ virtual void tearDown()
+ {
+ delete _finder;
+ _finder = NULL;
+ }
+
public:
virtual ~AbstractASTMatcherRule() {}