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/2] 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/2] 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"