@@ -4209,7 +4209,7 @@ void VariableMap::addVariable(const std::string& varname, bool globalNamespace)
42094209 it->second = ++mVarId ;
42104210}
42114211
4212- static bool setVarIdParseDeclaration (Token*& tok, const VariableMap& variableMap, bool executableScope)
4212+ static bool setVarIdParseDeclaration (Token*& tok, const VariableMap& variableMap, bool executableScope, Standards:: cstd_t cStandard )
42134213{
42144214 const Token* const tok1 = tok;
42154215 Token* tok2 = tok;
@@ -4229,7 +4229,9 @@ static bool setVarIdParseDeclaration(Token*& tok, const VariableMap& variableMap
42294229 }
42304230 if (tok2->isCpp () && Token::Match (tok2, " namespace|public|private|protected" ))
42314231 return false ;
4232- if (tok2->isCpp () && Token::simpleMatch (tok2, " decltype (" )) {
4232+ bool isC23 = tok2->isC () && cStandard >= Standards::C23;
4233+ if (((tok2->isCpp () || isC23) && Token::Match (tok2, " decltype|typeof (" )) ||
4234+ (tok2->isC () && Token::simpleMatch (tok2, " __typeof (" ))) {
42334235 typeCount = 1 ;
42344236 tok2 = tok2->linkAt (1 )->next ();
42354237 continue ;
@@ -4762,7 +4764,7 @@ void Tokenizer::setVarIdPass1()
47624764 }
47634765
47644766 try { /* Ticket #8151 */
4765- decl = setVarIdParseDeclaration (tok2, variableMap, scopeStack.top ().isExecutable );
4767+ decl = setVarIdParseDeclaration (tok2, variableMap, scopeStack.top ().isExecutable , mSettings . standards . c );
47664768 } catch (const Token * errTok) {
47674769 syntaxError (errTok);
47684770 }
@@ -4782,11 +4784,19 @@ void Tokenizer::setVarIdPass1()
47824784 variableMap.map (true ),
47834785 mTemplateVarIdUsage );
47844786 }
4785- if (Token *declTypeTok = Token::findsimplematch (tok, " decltype (" , tok2)) {
4786- for (Token *declTok = declTypeTok->linkAt (1 ); declTok != declTypeTok; declTok = declTok->previous ()) {
4787- if (declTok->isName () && !Token::Match (declTok->previous (), " ::|." ) && variableMap.hasVariable (declTok->str ()))
4788- declTok->varId (variableMap.map (false ).find (declTok->str ())->second );
4789- }
4787+ }
4788+
4789+ Token *declTypeTok = nullptr ;
4790+ if (cpp || mSettings .standards .c >= Standards::C23) {
4791+ declTypeTok = Token::findmatch (tok, " decltype|typeof (" , tok2);
4792+ } else {
4793+ declTypeTok = Token::findsimplematch (tok, " __typeof (" );
4794+ }
4795+
4796+ if (declTypeTok) {
4797+ for (Token *declTok = declTypeTok->linkAt (1 ); declTok != declTypeTok; declTok = declTok->previous ()) {
4798+ if (declTok->isName () && !Token::Match (declTok->previous (), " ::|." ) && variableMap.hasVariable (declTok->str ()))
4799+ declTok->varId (variableMap.map (false ).find (declTok->str ())->second );
47904800 }
47914801 }
47924802
0 commit comments