From ba44a2501e29e2d704c8e4a37b210b5665539aaf Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:25:11 +0100 Subject: [PATCH 1/4] Update symboldatabase.cpp --- lib/symboldatabase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e98b7127498..5a19229b89f 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3731,7 +3731,8 @@ bool Variable::arrayDimensions(const Settings& settings, bool& isContainer) // TODO: only perform when ValueFlow is enabled // TODO: collect timing information for this call? ValueFlow::valueFlowConstantFoldAST(const_cast(dimension_.tok), settings); - if (dimension_.tok && dimension_.tok->hasKnownIntValue()) { + if (dimension_.tok && (dimension_.tok->hasKnownIntValue() || + (dimension_.tok->isTemplateArg() && !dimension_.tok->values().empty()))) { dimension_.num = dimension_.tok->getKnownIntValue(); dimension_.known = true; } From 56abf8588eb64507874153fdbfbab3536a9ea494 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:26:38 +0100 Subject: [PATCH 2/4] Update testother.cpp --- test/testother.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index b0a76891dd1..0f88cb3b9e5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10994,6 +10994,13 @@ class TestOther : public TestFixture { " C(A x_, B y_) : x(x_), y(y_) {}\n" "};\n"); ASSERT_EQUALS("", errout_str()); // don't crash + + check("template \n" // #13537 + " struct S {\n" + " T a[N];\n" + "};\n" + "void f(S s) {}\n"); + ASSERT_EQUALS("", errout_str()); } void checkComparisonFunctionIsAlwaysTrueOrFalse() { From 83a2b9e07b8edd3d15e892450daed7a5f7236831 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:57:58 +0100 Subject: [PATCH 3/4] Update symboldatabase.cpp --- lib/symboldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5a19229b89f..d6afabd2886 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3731,7 +3731,7 @@ bool Variable::arrayDimensions(const Settings& settings, bool& isContainer) // TODO: only perform when ValueFlow is enabled // TODO: collect timing information for this call? ValueFlow::valueFlowConstantFoldAST(const_cast(dimension_.tok), settings); - if (dimension_.tok && (dimension_.tok->hasKnownIntValue() || + if (dimension_.tok && (dimension_.tok->hasKnownIntValue() || (dimension_.tok->isTemplateArg() && !dimension_.tok->values().empty()))) { dimension_.num = dimension_.tok->getKnownIntValue(); dimension_.known = true; From f38c566d219ab6dbb9de1f2cb48508517e6da2c2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:20:21 +0100 Subject: [PATCH 4/4] Update testother.cpp --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index 0f88cb3b9e5..cd4b85c718d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10999,7 +10999,7 @@ class TestOther : public TestFixture { " struct S {\n" " T a[N];\n" "};\n" - "void f(S s) {}\n"); + "void f(S s) {}\n"); ASSERT_EQUALS("", errout_str()); }