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

This commit is contained in:
chrchr-github 2023-03-12 15:39:02 +01:00 committed by GitHub
parent e2f38fdaf3
commit 980c92d19d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -5552,7 +5552,10 @@ void Tokenizer::removeMacrosInGlobalScope()
if (tok->str() == "(") {
tok = tok->link();
if (Token::Match(tok, ") %type% {") &&
!Token::Match(tok->next(), "const|namespace|class|struct|union|noexcept|override|final|volatile|mutable"))
!tok->next()->isStandardType() &&
!tok->next()->isKeyword() &&
!Token::Match(tok->next(), "override|final") &&
tok->next()->isUpperCaseName())
tok->deleteNext();
}

View File

@ -561,7 +561,7 @@ static bool iscpp11init_impl(const Token * const tok)
nameToken = nameToken->link()->previous();
if (nameToken->str() == "]") {
const Token* newTok = nameToken->link()->previous();
while (Token::Match(newTok, "%type%") && !newTok->isKeyword())
while (Token::Match(newTok, "%type%|::") && !newTok->isKeyword())
newTok = newTok->previous();
if (Token::simpleMatch(newTok, "new"))
return true;

View File

@ -5256,6 +5256,15 @@ private:
"\n"
"BOOL CSetProgsAdvDlg::OnInitDialog() {}"),
InternalError);
ASSERT_EQUALS("struct S {\n"
"S ( ) : p { new ( malloc ( 4 ) ) int { } } { }\n"
"int * p ;\n"
"} ;",
tokenizeAndStringify("struct S {\n"
" S() : p{new (malloc(4)) int{}} {}\n"
" int* p;\n"
"};\n"));
}
void addSemicolonAfterUnknownMacro() {
@ -7563,6 +7572,20 @@ private:
"{ void",
TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("struct S {\n"
" std::uint8_t* p;\n"
" S() : p{ new std::uint8_t[1]{} } {}\n"
"};\n",
"{ } } {",
TokenImpl::Cpp11init::CPP11INIT);
testIsCpp11init("struct S {\n"
" S() : p{new (malloc(4)) int{}} {}\n"
" int* p;\n"
"};\n",
"{ } } {",
TokenImpl::Cpp11init::CPP11INIT);
ASSERT_NO_THROW(tokenizeAndStringify("template<typename U> struct X {};\n" // don't crash
"template<typename T> auto f(T t) -> X<decltype(t + 1)> {}\n"));
#undef testIsCpp11init