diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4ef21f419..8bded705e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10974,8 +10974,14 @@ void Tokenizer::simplifyAttribute() Token *functok = nullptr; if (Token::Match(after, "%name%|*")) { Token *ftok = after; - while (Token::Match(ftok, "%name%|* !!(")) + while (Token::Match(ftok, "%name%|::|<|* !!(")) { + if (ftok->str() == "<") { + ftok = ftok->findClosingBracket(); + if (!ftok) + break; + } ftok = ftok->next(); + } if (Token::Match(ftok, "%name% (")) functok = ftok; } else if (Token::Match(after, "[;{=:]")) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 2a2d540ae..245ee2522 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -241,6 +241,9 @@ private: // remove calling convention __cdecl, __stdcall, ... TEST_CASE(simplifyCallingConvention); + // remove __attribute, __attribute__ + TEST_CASE(simplifyAttribute); + TEST_CASE(simplifyFunctorCall); TEST_CASE(simplifyFunctionPointer); // ticket #5339 (simplify function pointer after comma) @@ -4942,6 +4945,16 @@ private: ASSERT_EQUALS("enum E { CALLBACK } ;", tok("enum E { CALLBACK } ;", true, Settings::Unix32)); } + void simplifyAttribute() { + ASSERT_EQUALS("int f ( ) ;", tok("__attribute__ ((visibility(\"default\"))) int f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("__attribute__((visibility(\"default\"))) int f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("__attribute ((visibility(\"default\"))) int f();", true)); + ASSERT_EQUALS("int f ( ) ;", tok("__attribute__ ((visibility(\"default\"))) __attribute__ ((warn_unused_result)) int f();", true)); + ASSERT_EQUALS("blah :: blah f ( ) ;", tok("__attribute__ ((visibility(\"default\"))) blah::blah f();", true)); + ASSERT_EQUALS("template < T > Result < T > f ( ) ;", tok("template __attribute__ ((warn_unused_result)) Result f();", true)); + ASSERT_EQUALS("template < T , U > Result < T , U > f ( ) ;", tok("template __attribute__ ((warn_unused_result)) Result f();", true)); + } + void simplifyFunctorCall() { ASSERT_EQUALS("IncrementFunctor ( ) ( a ) ;", tok("IncrementFunctor()(a);", true)); }