Fixed #7266 (False positive shiftTooManyBits with macros)

This commit is contained in:
Daniel Marjamäki 2016-01-10 20:44:52 +01:00
parent b3208fb4b3
commit 4269702755
2 changed files with 11 additions and 1 deletions

View File

@ -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<<y)
if (_tokenizer->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;

View File

@ -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() {