Skip to content

Commit 46781df

Browse files
Fix #13537 FP passedByValue for template type (danmar#7195)
The same logic also exists in `setArrayDimensionsUsingValueFlow()` (not changed yet).
1 parent 93fd884 commit 46781df

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3731,7 +3731,8 @@ bool Variable::arrayDimensions(const Settings& settings, bool& isContainer)
37313731
// TODO: only perform when ValueFlow is enabled
37323732
// TODO: collect timing information for this call?
37333733
ValueFlow::valueFlowConstantFoldAST(const_cast<Token *>(dimension_.tok), settings);
3734-
if (dimension_.tok && dimension_.tok->hasKnownIntValue()) {
3734+
if (dimension_.tok && (dimension_.tok->hasKnownIntValue() ||
3735+
(dimension_.tok->isTemplateArg() && !dimension_.tok->values().empty()))) {
37353736
dimension_.num = dimension_.tok->getKnownIntValue();
37363737
dimension_.known = true;
37373738
}

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11062,6 +11062,13 @@ class TestOther : public TestFixture {
1106211062
" C(A<T> x_, B<T> y_) : x(x_), y(y_) {}\n"
1106311063
"};\n");
1106411064
ASSERT_EQUALS("", errout_str()); // don't crash
11065+
11066+
check("template <typename T, int N>\n" // #13537
11067+
" struct S {\n"
11068+
" T a[N];\n"
11069+
"};\n"
11070+
"void f(S<char, 3> s) {}\n");
11071+
ASSERT_EQUALS("", errout_str());
1106511072
}
1106611073

1106711074
void checkComparisonFunctionIsAlwaysTrueOrFalse() {

0 commit comments

Comments
 (0)