Fix crash in iscpp11init_impl() (#4743)

This commit is contained in:
chrchr-github 2023-01-26 22:25:49 +01:00 committed by GitHub
parent bea6aec2b2
commit ca0c13e27d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

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

View File

@ -7654,6 +7654,9 @@ private:
"};\n",
"{ } }",
TokenImpl::Cpp11init::NOINIT);
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
}
};