From 2d4285afdcec7c0454e578de32abb59a24d0c54d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:49:36 +0200 Subject: [PATCH 1/8] Update tokenize.cpp --- lib/tokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bbcd1bd6b89..504ee511241 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9482,7 +9482,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"))) par = par->previous(); if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings continue; From b08e700169cf3cc2c3bfe19ccd54f1d1619fa6e9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:50:47 +0200 Subject: [PATCH 2/8] Update testtokenize.cpp --- test/testtokenize.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d5c770169e4..8f4aa93f6b1 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2030,6 +2030,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 "(..)" From 601749824187e5404abb9aaeb74217421c09348f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:26:44 +0100 Subject: [PATCH 3/8] Update testtokenize.cpp [skip ci] --- test/testtokenize.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 8f4aa93f6b1..63a6cb30b9e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2034,11 +2034,18 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("struct D : B {\n" // #15126 "void f ( ) override { try { } catch ( ... ) { } }\n" "void g ( ) final { try { } catch ( ... ) { } }\n" + "void i ( ) & override { try { } catch ( ... ) { } }\n" + "void j ( ) const && override { try { } catch ( ... ) { } }\n" + "auto k ( ) . std :: nullptr_t override { try { } catch ( ... ) { } }\n" "} ;", tokenizeAndStringify("struct D : B {\n" " void f() override try {} catch (...) {}\n" " void g() final try {} catch (...) {}\n" + " void i() & override try {} catch (...) {}\n" + " void j() const && override try {} catch (...) {}\n" + " auto k() -> std::nullptr_t override try {} catch (...) {}\n" "};\n")); + ASSERT_EQUALS("[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\n", errout_str()); } // Simplify "((..))" into "(..)" From 638c0daf858d7136bc68da0df6fafcf4c6bdeb0b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:28:03 +0100 Subject: [PATCH 4/8] Update tokenlist.cpp [skip ci] --- lib/tokenlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 26b24d649c8..ee10b8b4887 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -2379,7 +2379,7 @@ const Token * TokenList::isFunctionHead(const Token *tok, const std::string &suf tok = tok->linkAt(1)->next(); if (Token::Match(tok, "%name% (") && tok->isUpperCaseName()) tok = tok->linkAt(1)->next(); - if (tok && tok->originalName() == "->") { // trailing return type + if (tok && (tok->str() == "->" || tok->originalName() == "->")) { // trailing return type for (tok = tok->next(); tok && !Token::Match(tok, ";|{|override|final|}|)|]"); tok = tok->next()) if (tok->link() && Token::Match(tok, "<|[|(")) tok = tok->link(); From bb811bc55bf72a0dea9206988a04ebdf792934a9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 26 Oct 2026 08:28:45 +0100 Subject: [PATCH 5/8] Update tokenize.cpp --- lib/tokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 504ee511241..1c29bc1046d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9482,7 +9482,7 @@ void Tokenizer::simplifyFunctionTryCatch() if (!Token::Match(tok, "try {|:")) continue; const Token* par = tok->previous(); - while (par && (par->isKeyword() || Token::Match(par, "final|override"))) + while (par && (par->isKeyword() || Token::Match(par, "%name%|&|&&|->|::"))) par = par->previous(); if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings continue; From 5391d031beddc8d5971e3bca47aff3a07068cc3d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 26 Oct 2026 12:36:50 +0100 Subject: [PATCH 6/8] Update tokenize.cpp --- lib/tokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1c29bc1046d..447920a5799 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9482,7 +9482,7 @@ void Tokenizer::simplifyFunctionTryCatch() if (!Token::Match(tok, "try {|:")) continue; const Token* par = tok->previous(); - while (par && (par->isKeyword() || Token::Match(par, "%name%|&|&&|->|::"))) + while (par && !Token::Match(par, "[);]"))) par = par->previous(); if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings continue; From 1affb74842185aa5749585643ac9ce2d797e680a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:15:08 +0100 Subject: [PATCH 7/8] Update tokenize.cpp --- lib/tokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 447920a5799..b6d79b6c743 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9482,7 +9482,7 @@ void Tokenizer::simplifyFunctionTryCatch() if (!Token::Match(tok, "try {|:")) continue; const Token* par = tok->previous(); - while (par && !Token::Match(par, "[);]"))) + while (par && !Token::Match(par, "[);]")) par = par->previous(); if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings continue; From d3c04bf411341589e5df02d2db7b390aa6a5a307 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 7 Nov 2026 19:36:38 +0100 Subject: [PATCH 8/8] Fix --- lib/tokenize.cpp | 9 ++++++++- test/testtokenize.cpp | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b6d79b6c743..6063e313f2d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9482,8 +9482,15 @@ void Tokenizer::simplifyFunctionTryCatch() if (!Token::Match(tok, "try {|:")) continue; const Token* par = tok->previous(); - while (par && !Token::Match(par, "[);]")) + while (par && !Token::Match(par, "[);]")) { + if (par->str() == ">") { + if (const Token* ob = par->findOpeningBracket()) { + par = ob; + continue; + } + } par = par->previous(); + } if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 63a6cb30b9e..3cf00724cf8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2037,6 +2037,7 @@ class TestTokenizer : public TestFixture { "void i ( ) & override { try { } catch ( ... ) { } }\n" "void j ( ) const && override { try { } catch ( ... ) { } }\n" "auto k ( ) . std :: nullptr_t override { try { } catch ( ... ) { } }\n" + "auto l ( ) . W < decltype ( 1 ) > override { try { } catch ( ... ) { } }\n" "} ;", tokenizeAndStringify("struct D : B {\n" " void f() override try {} catch (...) {}\n" @@ -2044,8 +2045,11 @@ class TestTokenizer : public TestFixture { " void i() & override try {} catch (...) {}\n" " void j() const && override try {} catch (...) {}\n" " auto k() -> std::nullptr_t override try {} catch (...) {}\n" + " auto l() -> W override try {} catch (...) {}\n" "};\n")); - ASSERT_EQUALS("[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:6:5]: (debug) auto token with no type. [autoNoType]\n" + "[test.cpp:7:5]: (debug) auto token with no type. [autoNoType]\n", + errout_str()); } // Simplify "((..))" into "(..)"