diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0c1070b9a2f..2d8a5eb9ae8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8911,8 +8911,12 @@ Token* Tokenizer::getAttributeFuncTok(Token* tok, bool gccattr) const { Token *prev = tok->previous(); while (Token::Match(prev, "%name%")) prev = prev->previous(); - if (Token::simpleMatch(prev, ")") && Token::Match(prev->link()->previous(), "%name% (")) - return prev->link()->previous(); + if (Token::simpleMatch(prev, ")")) { + if (Token::Match(prev->link()->previous(), "%name% (")) + return prev->link()->previous(); + if (Token::Match(prev->link()->tokAt(-2), "%name% ) (")) + return prev->link()->tokAt(-2); + } if (Token::simpleMatch(prev, ")") && Token::Match(prev->link()->tokAt(-2), "operator %op% (") && isCPP()) return prev->link()->tokAt(-2); if ((!prev || Token::Match(prev, "[;{}*]")) && Token::Match(tok->previous(), "%name%")) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index d4d79f4124a..3cb4dd7c24f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1317,6 +1317,7 @@ class TestSimplifyTokens : public TestFixture { ASSERT_EQUALS("blah :: blah f ( ) ;", tok("__attribute__ ((visibility(\"default\"))) blah::blah f();")); ASSERT_EQUALS("template < T > Result < T > f ( ) ;", tok("template __attribute__ ((warn_unused_result)) Result f();")); ASSERT_EQUALS("template < T , U > Result < T , U > f ( ) ;", tok("template __attribute__ ((warn_unused_result)) Result f();")); + ASSERT_EQUALS("void ( * fp ) ( ) ; fp = nullptr ;", tok("typedef void (*fp_t)() __attribute__((noreturn)); fp_t fp = nullptr;")); // #12137 } void simplifyFunctorCall() {