Fix #11332 Function::addArguments found argument 'b' with varid 0 wit… (#4506)

* Fix #11332 Function::addArguments found argument 'b' with varid 0 with lambda parameter

* Fix varid0 warning
This commit is contained in:
chrchr-github 2022-09-26 18:21:21 +02:00 committed by GitHub
parent fc39a4d1bb
commit 64f3f85804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -4563,7 +4563,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con
}
// skip const|volatile|static|mutable|extern
while (tok->isKeyword() && Token::Match(tok, "const|constexpr|volatile|static|mutable|extern")) {
while (tok && tok->isKeyword() && Token::Match(tok, "const|constexpr|volatile|static|mutable|extern")) {
tok = tok->next();
}
@ -4580,7 +4580,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess, con
return typeend->linkAt(1);
}
if (tok->isKeyword() && Token::Match(tok, "class|struct|union|enum")) {
while (tok && tok->isKeyword() && Token::Match(tok, "class|struct|union|enum")) {
tok = tok->next();
}

View File

@ -3973,7 +3973,7 @@ void Tokenizer::setVarIdPass1()
Token::Match(tok, "[;{}]") ||
(tok->str() == "(" && isFunctionHead(tok,"{")) ||
(tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) ||
(tok->str() == "," && (!scopeStack.top().isExecutable || inlineFunction)) ||
(tok->str() == "," && (!scopeStack.top().isExecutable || inlineFunction || !tok->previous()->varId())) ||
(tok->isName() && endsWith(tok->str(), ':')))) {
// No variable declarations in sizeof

View File

@ -379,6 +379,7 @@ private:
TEST_CASE(enum8);
TEST_CASE(enum9);
TEST_CASE(enum10); // #11001
TEST_CASE(enum11);
TEST_CASE(sizeOfType);
@ -5367,6 +5368,11 @@ private:
ASSERT_EQUALS(Y->value, 1);
}
void enum11() {
check("enum class E;\n");
ASSERT_EQUALS("", errout.str());
}
void sizeOfType() {
// #7615 - crash in Symboldatabase::sizeOfType()
GET_SYMBOL_DB("enum e;\n"

View File

@ -2761,6 +2761,16 @@ private:
"5: } ;\n";
ASSERT_EQUALS(exp, tokenize(code));
}
// # 11332
{
const char code[] = "auto a() {\n"
" return [](int, int b) {};\n"
"}\n";
const char exp[] = "1: auto a ( ) {\n"
"2: return [ ] ( int , int b@1 ) { } ;\n"
"3: }\n";
ASSERT_EQUALS(exp, tokenize(code));
}
}
void varid_lambda_mutable() {