From 23ccf816e261d85249aeceecbedcb335c581735f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 2 Oct 2026 13:30:54 +0200 Subject: [PATCH 1/5] Update templatesimplifier.cpp --- lib/templatesimplifier.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index c636cf72c43..ee6bc853d0c 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -401,6 +401,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) return 0; unsigned int level = 0; + unsigned int inTernary = 0; while (tok) { // skip template template @@ -460,8 +461,16 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) } // Skip '=', '?', ':' - if (Token::Match(tok, "=|?|:")) + if (Token::Match(tok, "=|?|:")) { + if (tok->str()[0] == '?') + ++inTernary; + else if (tok->str()[0] == ':') { + if (inTernary == 0) + return 0; + --inTernary; + } tok = tok->next(); + } if (!tok) return 0; From 0285eee3156a607a090604aa48bf226fbb2f73a6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 2 Oct 2026 13:32:04 +0200 Subject: [PATCH 2/5] Update testtokenize.cpp --- test/testtokenize.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 88183c3db5b..37dc0d1437c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -240,6 +240,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(vardecl33); TEST_CASE(vardecl34); TEST_CASE(vardecl35); + TEST_CASE(vardecl36); TEST_CASE(vardecl_stl_1); TEST_CASE(vardecl_stl_2); TEST_CASE(vardecl_stl_3); @@ -3035,6 +3036,28 @@ class TestTokenizer : public TestFixture { } } + void vardecl36() { + const char code[] = "struct S {\n" + " bool f() const;\n" + " int g() const;\n" + " int x, y;\n" + "};\n" + "bool S::f() const {\n" + " const bool b = x ? g() < 0 : 0 > y;\n" + " return b;\n" + "}\n"; + const char expected[] = "struct S {\n" + "bool f ( ) const ;\n" + "int g ( ) const ;\n" + "int x ; int y ;\n" + "} ;\n" + "bool S :: f ( ) const {\n" + "const bool b = x ? ( g ( ) < 0 ) : 0 > y ;\n" + "return b ;\n" + "}"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + void volatile_variables() { { const char code[] = "volatile int a=0;\n" From f64b7df352c2ced9fcfeb4627d65c9fb71ffdd4c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 5 Oct 2026 16:47:43 +0200 Subject: [PATCH 3/5] Update templatesimplifier.cpp [skip ci] --- lib/templatesimplifier.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index ee6bc853d0c..586eb65cda7 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -394,14 +394,14 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) return 0; if (tok->str() != "<") return 0; - if (Token::Match(tok->previous(), "%var% <")) + if (Token::Match(tok->previous(), "%var%|) <")) return 0; tok = tok->next(); if (!tok || tok->str() == ">") return 0; unsigned int level = 0; - unsigned int inTernary = 0; + unsigned int ternaryLevel = 0; while (tok) { // skip template template @@ -463,11 +463,11 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) // Skip '=', '?', ':' if (Token::Match(tok, "=|?|:")) { if (tok->str()[0] == '?') - ++inTernary; + ++ternaryLevel; else if (tok->str()[0] == ':') { - if (inTernary == 0) + if (ternaryLevel == 0) return 0; - --inTernary; + --ternaryLevel; } tok = tok->next(); } From 4cdec25935e8854f2d5d231c7cf975f32bf4a4eb Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 5 Oct 2026 16:49:12 +0200 Subject: [PATCH 4/5] Update testtokenize.cpp --- test/testtokenize.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 37dc0d1437c..ef64bef7d89 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3037,14 +3037,19 @@ class TestTokenizer : public TestFixture { } void vardecl36() { - const char code[] = "struct S {\n" - " bool f() const;\n" + const char code[] = "struct S {\n" // #15086 + " bool f1() const;\n" + " bool f2() const;\n" " int g() const;\n" " int x, y;\n" "};\n" - "bool S::f() const {\n" + "bool S::f1() const {\n" " const bool b = x ? g() < 0 : 0 > y;\n" " return b;\n" + "}\n" + "bool S::f2() const {\n" + " const bool b = g() < x ? x != y : 0 > y;\n" + " return b;\n" "}\n"; const char expected[] = "struct S {\n" "bool f ( ) const ;\n" From f8ec234e56c9ed940696b021555451f8eb099207 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 5 Oct 2026 16:58:02 +0200 Subject: [PATCH 5/5] Update testtokenize.cpp --- test/testtokenize.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ef64bef7d89..53fb71458ec 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3052,13 +3052,18 @@ class TestTokenizer : public TestFixture { " return b;\n" "}\n"; const char expected[] = "struct S {\n" - "bool f ( ) const ;\n" + "bool f1 ( ) const ;\n" + "bool f2 ( ) const ;\n" "int g ( ) const ;\n" "int x ; int y ;\n" "} ;\n" - "bool S :: f ( ) const {\n" + "bool S :: f1 ( ) const {\n" "const bool b = x ? ( g ( ) < 0 ) : 0 > y ;\n" "return b ;\n" + "}\n" + "bool S :: f2 ( ) const {\n" + "const bool b = g ( ) < x ? x != y : 0 > y ;\n" + "return b ;\n" "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); }