Partial fix for #11378 internalAstError regressions (iscpp11init) (#4700)

This commit is contained in:
chrchr-github 2023-01-18 17:09:55 +01:00 committed by GitHub
parent 9cf934c10d
commit c4784a1552
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -637,7 +637,7 @@ static bool iscpp11init_impl(const Token * const tok)
return false; return false;
if (nameToken->str() == ")" && Token::simpleMatch(nameToken->link()->previous(), "decltype (") && if (nameToken->str() == ")" && Token::simpleMatch(nameToken->link()->previous(), "decltype (") &&
!Token::simpleMatch(nameToken->link()->tokAt(-2), ".")) !Token::simpleMatch(nameToken->link()->tokAt(-2), "."))
return true; nameToken = nameToken->link()->previous();
if (Token::simpleMatch(nameToken, ", {")) if (Token::simpleMatch(nameToken, ", {"))
return true; return true;
if (nameToken->str() == ">" && nameToken->link()) if (nameToken->str() == ">" && nameToken->link())
@ -667,6 +667,8 @@ static bool iscpp11init_impl(const Token * const tok)
endtok = nameToken->linkAt(1)->linkAt(1); endtok = nameToken->linkAt(1)->linkAt(1);
else if (Token::Match(nameToken->previous(), "%name%|> ( {")) else if (Token::Match(nameToken->previous(), "%name%|> ( {"))
endtok = nameToken->linkAt(1); endtok = nameToken->linkAt(1);
else if (Token::simpleMatch(nameToken, "decltype") && nameToken->linkAt(1))
endtok = nameToken->linkAt(1)->linkAt(1);
else else
return false; return false;
if (Token::Match(nameToken, "else|try|do|const|constexpr|override|volatile|&|&&")) if (Token::Match(nameToken, "else|try|do|const|constexpr|override|volatile|&|&&"))
@ -689,7 +691,7 @@ static bool iscpp11init_impl(const Token * const tok)
if (!Token::simpleMatch(endtok, "} ;")) if (!Token::simpleMatch(endtok, "} ;"))
return true; return true;
const Token *prev = nameToken; const Token *prev = nameToken;
while (Token::Match(prev, "%name%|::|:|<|>|,|%num%|%cop%")) { while (Token::Match(prev, "%name%|::|:|<|>|(|)|,|%num%|%cop%")) {
if (Token::Match(prev, "class|struct|union|enum")) if (Token::Match(prev, "class|struct|union|enum"))
return false; return false;

View File

@ -7557,6 +7557,13 @@ private:
"};\n", "};\n",
"{ } }", "{ } }",
TokenImpl::Cpp11init::NOINIT); TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("struct S { int i; } s;\n"
"struct T : decltype (s) {\n"
" T() : decltype(s) ({ 0 }) { }\n"
"};\n",
"{ } }",
TokenImpl::Cpp11init::NOINIT);
#undef testIsCpp11init #undef testIsCpp11init
} }
}; };