diff --git a/lib/checktype.cpp b/lib/checktype.cpp index ec39223b6..61c641d8d 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -47,7 +47,11 @@ void CheckType::checkTooBigBitwiseShift() const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; - for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { + // C++ and macro: OUT(x<isCPP() && Token::Match(tok, "[;{}] %name% (") && Token::Match(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function()) + tok = tok->linkAt(2); + if (!Token::Match(tok, "<<|>>|<<=|>>=")) continue; diff --git a/test/testtype.cpp b/test/testtype.cpp index 53b2e591b..13c37917c 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -94,6 +94,12 @@ private: "const int h = hoo<100>(1);", &settings); ASSERT_EQUALS("[test.cpp:4]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n" "[test.cpp:1]: (error) Shifting 32-bit value by 100 bits is undefined behaviour\n", errout.str()); + + // #7266: C++, shift in macro + check("void f(int x) {\n" + " UINFO(x << 1234);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkIntegerOverflow() {