Partial fix for #5555. Improved pure/const attributes handling

This commit is contained in:
Robert Reif 2014-03-14 19:06:05 +01:00 committed by Daniel Marjamäki
parent e26bd5b99c
commit 2ba3a36f2c
2 changed files with 28 additions and 5 deletions

View File

@ -9127,14 +9127,24 @@ void Tokenizer::simplifyAttribute()
tok->next()->link()->next()->isAttributeUnused(true);
}
// type func(...) __attribute__((pure));
if (Token::simpleMatch(tok->tokAt(2), "( pure )")) {
tok->previous()->link()->previous()->isAttributePure(true);
// type func(...) __attribute__((pure));
if (tok->next()->link()->next()->str() == ";")
tok->previous()->link()->previous()->isAttributePure(true);
// type __attribute__((pure)) func() { }
else
tok->next()->link()->next()->isAttributePure(true);
}
// type func(...) __attribute__((const));
if (Token::simpleMatch(tok->tokAt(2), "( const )")) {
tok->previous()->link()->previous()->isAttributeConst(true);
// type func(...) __attribute__((const));
if (tok->next()->link()->next()->str() == ";")
tok->previous()->link()->previous()->isAttributeConst(true);
// type __attribute__((const)) func() { }
else
tok->next()->link()->next()->isAttributeConst(true);
}
Token::eraseTokens(tok, tok->next()->link()->next());

View File

@ -4835,12 +4835,25 @@ private:
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
}
check("void GetValue() __attribute__((const)) { return X; }\n"
check("void GetValue() { return rand(); }\n"
"void foo() {\n"
" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void __attribute__((const)) GetValue() { return X; }\n"
"void foo() {\n"
" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (style) Same expression on both sides of '||'.\n", errout.str());
check("void GetValue() __attribute__((const));\n"
"void GetValue() { return X; }\n"
"void foo() {\n"
" if ((GetValue() == 0) || (GetValue() == 0)) { dostuff(); }\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:4]: (style) Same expression on both sides of '||'.\n", errout.str());
check("void foo() {\n"
" if (str == \"(\" || str == \"(\") {}\n"
"}");