Skip to content

Commit

Permalink
Fix #13052 FP passedByValue for array of vectors (reopened) (#7005)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 23, 2024
1 parent ce16b8d commit 1e79d8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,11 @@ void CheckOther::checkPassByReference()
if (inconclusive && !mSettings->certainty.isEnabled(Certainty::inconclusive))
continue;

if (var->isArray() && var->getTypeName() != "std::array")
continue;

const bool isConst = var->isConst();
if (isConst && !var->isArray()) {
if (isConst) {
passedByValueError(var, inconclusive, isRangeBasedFor);
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2435,8 +2435,10 @@ class TestOther : public TestFixture {
ASSERT_EQUALS("", errout_str());

check("void f(const std::vector<int> v[2]);\n" // #13052
"int g(const std::array<std::vector<int>, 2> a) { return a[0][0]; }\n");
ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'a' should be passed by const reference.\n", errout_str());
"void g(const std::vector<int> v[2]);\n"
"void g(const std::vector<int> v[2]) {}\n"
"int h(const std::array<std::vector<int>, 2> a) { return a[0][0]; }\n");
ASSERT_EQUALS("[test.cpp:4]: (performance) Function parameter 'a' should be passed by const reference.\n", errout_str());

/*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();
check("using ui64 = unsigned __int64;\n"
Expand Down

0 comments on commit 1e79d8b

Please sign in to comment.