diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 31f38900f..a590da6fd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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()); diff --git a/test/testother.cpp b/test/testother.cpp index 834ef898c..231c765a4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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" "}");