Fix internal error "Unexpected tokens in initializer" with anonymous namespace (#4577)

Co-authored-by: Gerbo Engels <gerbo.engels@ortec-finance.com>
This commit is contained in:
gerboengels 2022-11-05 22:41:13 +01:00 committed by GitHub
parent e45e5f9f15
commit bd95efc987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -675,7 +675,7 @@ static bool iscpp11init_impl(const Token * const tok)
return false;
if (Token::simpleMatch(nameToken->previous(), ". void {") && nameToken->previous()->originalName() == "->")
return false; // trailing return type. The only function body that can contain no semicolon is a void function.
if (Token::simpleMatch(nameToken->previous(), "namespace"))
if (Token::simpleMatch(nameToken->previous(), "namespace") || Token::simpleMatch(nameToken, "namespace") /*anonymous namespace*/)
return false;
if (endtok != nullptr && !Token::Match(nameToken, "return|:")) {
// If there is semicolon between {..} this is not a initlist

View File

@ -7483,6 +7483,13 @@ private:
testIsCpp11init("class X{}", // forgotten ; so not properly recognized as a class
"{ }",
TokenImpl::Cpp11init::CPP11INIT);
testIsCpp11init("namespace abc::def { TEST(a, b) {} }",
"{ TEST",
TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("namespace { TEST(a, b) {} }", // anonymous namespace
"{ TEST",
TokenImpl::Cpp11init::NOINIT);
#undef testIsCpp11init
}
};