From 46781df9657bfd31922e635466c3951af96f6a85 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 12 Jan 2025 23:15:27 +0100 Subject: [PATCH] Fix #13537 FP passedByValue for template type (#7195) The same logic also exists in `setArrayDimensionsUsingValueFlow()` (not changed yet). --- lib/symboldatabase.cpp | 3 ++- test/testother.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 8008d40c4d1..2ad9d487599 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; } diff --git a/test/testother.cpp b/test/testother.cpp index 873ae8ef852..4dceade465e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11062,6 +11062,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() {