diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp index e904ea095..39a5ccfab 100644 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -81,12 +81,28 @@ void CheckInternal::checkTokenMatchPatterns() orInComplexPattern(tok, pattern, funcname); // Check for signs of complex patterns - if (pattern.find_first_of("[|%") != std::string::npos) + if (pattern.find_first_of("[|") != std::string::npos) continue; else if (pattern.find("!!") != std::string::npos) continue; - simplePatternError(tok, pattern, funcname); + bool complex = false; + size_t index = pattern.find('%'); + while (index != std::string::npos) { + if (pattern.length() <= index + 2) { + complex = true; + break; + } + if (pattern[index + 1] == 'o' && pattern[index + 2] == 'r') // %or% or %oror% + index = pattern.find('%', index + 1); + else { + complex = true; + break; + } + index = pattern.find('%', index+1); + } + if (!complex) + simplePatternError(tok, pattern, funcname); } } diff --git a/test/testinternal.cpp b/test/testinternal.cpp index 2dc66cf1e..9c0969990 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -76,6 +76,12 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " const Token *tok;\n" + " Token::Match(tok, \"%or%\");\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (warning) Found simple pattern inside Token::Match() call: \"%or%\"\n", errout.str()); + check("void f() {\n" " const Token *tok;\n" " Token::findmatch(tok, \";\");\n"