Skip to content

Commit 099d96f

Browse files
Fix #12137 syntaxError with attribute in typedef (#5612)
1 parent 63e00ea commit 099d96f

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/tokenize.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8911,8 +8911,12 @@ Token* Tokenizer::getAttributeFuncTok(Token* tok, bool gccattr) const {
89118911
Token *prev = tok->previous();
89128912
while (Token::Match(prev, "%name%"))
89138913
prev = prev->previous();
8914-
if (Token::simpleMatch(prev, ")") && Token::Match(prev->link()->previous(), "%name% ("))
8915-
return prev->link()->previous();
8914+
if (Token::simpleMatch(prev, ")")) {
8915+
if (Token::Match(prev->link()->previous(), "%name% ("))
8916+
return prev->link()->previous();
8917+
if (Token::Match(prev->link()->tokAt(-2), "%name% ) ("))
8918+
return prev->link()->tokAt(-2);
8919+
}
89168920
if (Token::simpleMatch(prev, ")") && Token::Match(prev->link()->tokAt(-2), "operator %op% (") && isCPP())
89178921
return prev->link()->tokAt(-2);
89188922
if ((!prev || Token::Match(prev, "[;{}*]")) && Token::Match(tok->previous(), "%name%"))

test/testsimplifytokens.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ class TestSimplifyTokens : public TestFixture {
13171317
ASSERT_EQUALS("blah :: blah f ( ) ;", tok("__attribute__ ((visibility(\"default\"))) blah::blah f();"));
13181318
ASSERT_EQUALS("template < T > Result < T > f ( ) ;", tok("template<T> __attribute__ ((warn_unused_result)) Result<T> f();"));
13191319
ASSERT_EQUALS("template < T , U > Result < T , U > f ( ) ;", tok("template<T, U> __attribute__ ((warn_unused_result)) Result<T, U> f();"));
1320+
ASSERT_EQUALS("void ( * fp ) ( ) ; fp = nullptr ;", tok("typedef void (*fp_t)() __attribute__((noreturn)); fp_t fp = nullptr;")); // #12137
13201321
}
13211322

13221323
void simplifyFunctorCall() {

0 commit comments

Comments
 (0)