Fix #12137 syntaxError with attribute in typedef (#5612)

This commit is contained in:
chrchr-github 2023-11-03 09:56:41 +01:00 committed by GitHub
parent 63e00ea918
commit 099d96ffa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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%"))

View File

@ -1317,6 +1317,7 @@ private:
ASSERT_EQUALS("blah :: blah f ( ) ;", tok("__attribute__ ((visibility(\"default\"))) blah::blah f();"));
ASSERT_EQUALS("template < T > Result < T > f ( ) ;", tok("template<T> __attribute__ ((warn_unused_result)) Result<T> f();"));
ASSERT_EQUALS("template < T , U > Result < T , U > f ( ) ;", tok("template<T, U> __attribute__ ((warn_unused_result)) Result<T, U> f();"));
ASSERT_EQUALS("void ( * fp ) ( ) ; fp = nullptr ;", tok("typedef void (*fp_t)() __attribute__((noreturn)); fp_t fp = nullptr;")); // #12137
}
void simplifyFunctorCall() {