Fix #11378 internalAstError regressions (iscpp11init) (#4580)

This commit is contained in:
chrchr-github 2022-11-12 22:25:05 +01:00 committed by GitHub
parent 8fb8e06003
commit e8b37235d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -692,7 +692,7 @@ static bool iscpp11init_impl(const Token * const tok)
return true;
const Token *prev = nameToken;
while (Token::Match(prev, "%name%|::|:|<|>|,")) {
if (Token::Match(prev, "class|struct"))
if (Token::Match(prev, "class|struct|union|enum"))
return false;
prev = prev->previous();
@ -996,8 +996,12 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
Token* curlyBracket = roundBracket->link()->next();
while (Token::Match(curlyBracket, "mutable|const|constexpr|consteval"))
curlyBracket = curlyBracket->next();
if (Token::simpleMatch(curlyBracket, "noexcept ("))
curlyBracket = curlyBracket->linkAt(1)->next();
if (Token::simpleMatch(curlyBracket, "noexcept")) {
if (Token::simpleMatch(curlyBracket->next(), "("))
curlyBracket = curlyBracket->linkAt(1)->next();
else
curlyBracket = curlyBracket->next();
}
if (curlyBracket && curlyBracket->originalName() == "->")
curlyBracket = findTypeEnd(curlyBracket->next());
if (curlyBracket && curlyBracket->str() == "{") {

View File

@ -6533,6 +6533,9 @@ private:
" return a < b;\n"
" });\n"
"}\n"));
// #11378
ASSERT_EQUALS("gT{(&[{= 0return", testAst("auto g = T{ [&]() noexcept -> int { return 0; } };"));
}
void astcase() {
@ -7493,6 +7496,10 @@ private:
testIsCpp11init("namespace { TEST(a, b) {} }", // anonymous namespace
"{ TEST",
TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("enum { e = decltype(s)::i };",
"{ e",
TokenImpl::Cpp11init::NOINIT);
#undef testIsCpp11init
}
};