Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9427,7 +9427,7 @@ void Tokenizer::simplifyFunctionTryCatch()
if (!Token::Match(tok, "try {|:"))
continue;
const Token* par = tok->previous();
while (par && par->isKeyword())
while (par && (par->isKeyword() || Token::Match(par, "final|override")))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

This loop still misses override or final after a ref-qualifier or a trailing return type. These still produce syntaxError:

struct E : B { void i() & override try {} catch (...) {} };
struct F : B { auto k() -> void override try {} catch (...) {} };

&/&& and -> type before try already fail in base without override, so this is a gap that existed before, not a regression. It may still be worth covering here, or noting in the ticket.

par = par->previous();
if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings
continue;
Expand Down
9 changes: 9 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,15 @@ class TestTokenizer : public TestFixture {
"void S::func() const\n"
"try { f(); }\n"
"catch (...) { g(); }\n"));

ASSERT_EQUALS("struct D : B {\n" // #15126
"void f ( ) override { try { } catch ( ... ) { } }\n"
"void g ( ) final { try { } catch ( ... ) { } }\n"
"} ;",
tokenizeAndStringify("struct D : B {\n"
" void f() override try {} catch (...) {}\n"
" void g() final try {} catch (...) {}\n"
"};\n"));
}

// Simplify "((..))" into "(..)"
Expand Down
Loading