Skip to content

Commit

Permalink
Fix #13537 FP passedByValue for template type (#7195)
Browse files Browse the repository at this point in the history
The same logic also exists in `setArrayDimensionsUsingValueFlow()` (not
changed yet).
  • Loading branch information
chrchr-github authored Jan 12, 2025
1 parent 93fd884 commit 46781df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token *>(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;
}
Expand Down
7 changes: 7 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11062,6 +11062,13 @@ class TestOther : public TestFixture {
" C(A<T> x_, B<T> y_) : x(x_), y(y_) {}\n"
"};\n");
ASSERT_EQUALS("", errout_str()); // don't crash

check("template <typename T, int N>\n" // #13537
" struct S {\n"
" T a[N];\n"
"};\n"
"void f(S<char, 3> s) {}\n");
ASSERT_EQUALS("", errout_str());
}

void checkComparisonFunctionIsAlwaysTrueOrFalse() {
Expand Down

0 comments on commit 46781df

Please sign in to comment.