Fix #11357 new internalAstError (#4564)

* Fix #11357 new internalAstError

* Format

* Handle scope operator

* Format

* Format
This commit is contained in:
chrchr-github 2022-10-25 21:50:37 +02:00 committed by GitHub
parent 3b5601dbea
commit b4e78e8ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -640,8 +640,17 @@ static bool iscpp11init_impl(const Token * const tok)
return true; return true;
} }
auto isCaseStmt = [](const Token* colonTok) {
if (!Token::Match(colonTok->tokAt(-1), "%name%|%num% :"))
return false;
const Token* caseTok = colonTok->tokAt(-2);
while (Token::Match(caseTok->tokAt(-1), "::|%name%"))
caseTok = caseTok->tokAt(-1);
return Token::simpleMatch(caseTok, "case");
};
const Token *endtok = nullptr; const Token *endtok = nullptr;
if (Token::Match(nameToken, "%name%|return|: {") && if (Token::Match(nameToken, "%name%|return|: {") && !isCaseStmt(nameToken) &&
(!Token::simpleMatch(nameToken->tokAt(2), "[") || findLambdaEndScope(nameToken->tokAt(2)))) (!Token::simpleMatch(nameToken->tokAt(2), "[") || findLambdaEndScope(nameToken->tokAt(2))))
endtok = nameToken->linkAt(1); endtok = nameToken->linkAt(1);
else if (Token::Match(nameToken,"%name% <") && Token::simpleMatch(nameToken->linkAt(1),"> {")) else if (Token::Match(nameToken,"%name% <") && Token::simpleMatch(nameToken->linkAt(1),"> {"))

View File

@ -6497,6 +6497,32 @@ private:
// #10831 // #10831
ASSERT_EQUALS("f{([= x{([=", testAst("void foo() { F f = [](t x = []() {}) {}; }")); ASSERT_EQUALS("f{([= x{([=", testAst("void foo() { F f = [](t x = []() {}) {}; }"));
// #11357
ASSERT_NO_THROW(tokenizeAndStringify("void f(std::vector<int>& v, bool c) {\n"
" std::sort(v.begin(), v.end(), [&c](const auto a, const auto b) {\n"
" switch (c) {\n"
" case false: {\n"
" if (a < b) {}\n"
" }\n"
" }\n"
" return a < b;\n"
" });\n"
"}\n"));
ASSERT_NO_THROW(tokenizeAndStringify("namespace N {\n"
" enum E : bool { F };\n"
"}\n"
"void f(std::vector<int>& v, bool c) {\n"
" std::sort(v.begin(), v.end(), [&c](const auto a, const auto b) {\n"
" switch (c) {\n"
" case N::E::F: {\n"
" if (a < b) {}\n"
" }\n"
" }\n"
" return a < b;\n"
" });\n"
"}\n"));
} }
void astcase() { void astcase() {