diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b7b409f32..d2564c9f7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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(); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index faa7387ad..4f415fdc4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 4769dd948..2d85fa8b9 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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" diff --git a/test/testvarid.cpp b/test/testvarid.cpp index d9805ffbe..a56cba921 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -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() {