Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,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;
Expand Down
23 changes: 23 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5256,6 +5256,15 @@ class TestTokenizer : public TestFixture {
"\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() {
Expand Down Expand Up @@ -7561,6 +7570,20 @@ class TestTokenizer : public TestFixture {
"{ 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
Expand Down