| 5171 | } |
| 5172 | |
| 5173 | const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess) |
| 5174 | { |
| 5175 | // Is it a throw..? |
| 5176 | if (tok->isKeyword() && Token::Match(tok, "throw %any% (") && |
| 5177 | Token::simpleMatch(tok->linkAt(2), ") ;")) { |
| 5178 | return tok->linkAt(2); |
| 5179 | } |
| 5180 | |
| 5181 | if (tok->isKeyword() && Token::Match(tok, "throw %any% :: %any% (") && |
| 5182 | Token::simpleMatch(tok->linkAt(4), ") ;")) { |
| 5183 | return tok->linkAt(4); |
| 5184 | } |
| 5185 | |
| 5186 | // friend? |
| 5187 | if (tok->isKeyword() && Token::Match(tok, "friend %type%") && tok->next()->varId() == 0) { |
| 5188 | const Token *next = Token::findmatch(tok->tokAt(2), ";|{"); |
| 5189 | if (next && next->str() == "{") |
| 5190 | next = next->link(); |
| 5191 | return next; |
| 5192 | } |
| 5193 | |
| 5194 | // skip const|volatile|static|mutable|extern |
| 5195 | while (tok && tok->isKeyword() && Token::Match(tok, "const|constexpr|volatile|static|mutable|extern")) { |
| 5196 | tok = tok->next(); |
| 5197 | } |
| 5198 | |
| 5199 | // the start of the type tokens does not include the above modifiers |
| 5200 | const Token *typestart = tok; |
| 5201 | |
| 5202 | // C++17 structured bindings |
| 5203 | if (tok && tok->isCpp() && (symdb.mSettings.standards.cpp >= Standards::CPP17) && Token::Match(tok, "auto &|&&| [")) { |
| 5204 | const Token *typeend = Token::findsimplematch(typestart, "[")->previous(); |
| 5205 | for (tok = typeend->tokAt(2); Token::Match(tok, "%name%|,"); tok = tok->next()) { |
| 5206 | if (tok->varId()) |
| 5207 | addVariable(tok, typestart, typeend, varaccess, nullptr, this); |
| 5208 | } |
| 5209 | return typeend->linkAt(1); |
| 5210 | } |
| 5211 | |
| 5212 | while (tok && tok->isKeyword() && Token::Match(tok, "class|struct|union|enum")) { |
| 5213 | tok = tok->next(); |
| 5214 | } |
| 5215 | |
| 5216 | // This is the start of a statement |
| 5217 | const Token *vartok = nullptr; |
| 5218 | const Token *typetok = nullptr; |
| 5219 | |
| 5220 | if (tok && isVariableDeclaration(tok, vartok, typetok)) { |
| 5221 | const Token* const orig = tok; |
| 5222 | // If the vartok was set in the if-blocks above, create a entry for this variable.. |
| 5223 | tok = vartok->next(); |
| 5224 | while (Token::Match(tok, "[|{")) |
| 5225 | tok = tok->link()->next(); |
| 5226 | |
| 5227 | if (vartok->varId() == 0) { |
| 5228 | if (!vartok->isBoolean()) |
| 5229 | symdb.debugMessage(vartok, "varid0", "Scope::checkVariable found variable \'" + vartok->str() + "\' with varid 0."); |
| 5230 | return tok; |
no test coverage detected