@@ -4783,7 +4783,7 @@ void Tokenizer::setVarId()
47834783#define NOTSTART_C " NOT" , " case" , " default" , " goto" , " not" , " return" , " sizeof" , " typedef"
47844784static const std::unordered_set<std::string> notstart_c = { NOTSTART_C };
47854785static const std::unordered_set<std::string> notstart_cpp = { NOTSTART_C ,
4786- " delete" , " friend" , " new" , " throw" , " using" , " virtual" , " explicit" , " const_cast" , " dynamic_cast" , " reinterpret_cast" , " static_cast" , " template" , " requires "
4786+ " delete" , " friend" , " new" , " throw" , " using" , " virtual" , " explicit" , " const_cast" , " dynamic_cast" , " reinterpret_cast" , " static_cast" , " template"
47874787};
47884788
47894789// Returns the end of the lambda that starts at tok in a constructor initializer list, or nullptr
@@ -4826,6 +4826,9 @@ void Tokenizer::setVarIdPass1()
48264826 const bool cpp = isCPP ();
48274827 // Variable declarations can't start with "return" etc.
48284828 const std::unordered_set<std::string>& notstart = (isC ()) ? notstart_c : notstart_cpp;
4829+ const auto isNotstart = [¬start](const Token* t) {
4830+ return notstart.find (t->str ()) != notstart.end () || (t->str () == " requires" && t->isKeyword ());
4831+ };
48294832
48304833 VariableMap variableMap;
48314834 std::map<nonneg int , std::map<std::string, nonneg int >> structMembers;
@@ -4989,7 +4992,8 @@ void Tokenizer::setVarIdPass1()
49894992 (tok->str () == " (" && TokenList::isFunctionHead (tok, " {" ))) {
49904993
49914994 // No variable declarations in sizeof and static_assert
4992- if (Token::Match (tok->previous (), " sizeof|static_assert|_Static_assert (" )) {
4995+ if (Token::Match (tok->previous (), " sizeof|_Static_assert (" ) ||
4996+ (Token::simpleMatch (tok->previous (), " static_assert (" ) && tok->previous ()->isKeyword ())) {
49934997 continue ;
49944998 }
49954999
@@ -5007,7 +5011,7 @@ void Tokenizer::setVarIdPass1()
50075011 break ;
50085012
50095013 // Variable declaration can't start with "return", etc
5010- if (notstart. find (tok2-> str ()) != notstart. end ( ))
5014+ if (isNotstart (tok2))
50115015 continue ;
50125016
50135017 if (!isC () && Token::simpleMatch (tok2, " const new" ))
@@ -5104,7 +5108,7 @@ void Tokenizer::setVarIdPass1()
51045108 !isPointerToArrayDeclarator (tok3->next (), variableMap)))) ||
51055109 tok3->isOp () ||
51065110 tok3->str () == " (" ||
5107- notstart. find (tok3-> str ()) != notstart. end ( )) {
5111+ isNotstart (tok3)) {
51085112 decl = true ;
51095113 break ;
51105114 }
@@ -5205,7 +5209,7 @@ void Tokenizer::setVarIdPass1()
52055209 for (end = tok->next (); Token::Match (end, " %name%|*|&|,|[|]|%num%" ); end = end->next ()) {}
52065210
52075211 // there are tokens which can't appear at the begin of a function declaration such as "return"
5208- const bool isNotstartKeyword = start->next () && notstart. find (start->strAt ( 1 )) != notstart. end ( );
5212+ const bool isNotstartKeyword = start->next () && isNotstart (start->next () );
52095213
52105214 // now check if it is a function (pointer) declaration
52115215 if ((Token::simpleMatch (start, " ) (" ) || Token::Match (start, " [;{}] %type% %name%|*" )) && par && Token::Match (end, " ) [;=]" ) && !isNotstartKeyword) {
0 commit comments