diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bd68edc2e..0a67cf12f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); } diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index ffcacf21f..7e322f797 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1ba8737c3..758590203 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 struct X {};\n" // don't crash "template auto f(T t) -> X {}\n")); #undef testIsCpp11init