Skip to content

Commit 1e79d8b

Browse files
Fix #13052 FP passedByValue for array of vectors (reopened) (danmar#7005)
1 parent ce16b8d commit 1e79d8b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/checkother.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,11 @@ void CheckOther::checkPassByReference()
14071407
if (inconclusive && !mSettings->certainty.isEnabled(Certainty::inconclusive))
14081408
continue;
14091409

1410+
if (var->isArray() && var->getTypeName() != "std::array")
1411+
continue;
1412+
14101413
const bool isConst = var->isConst();
1411-
if (isConst && !var->isArray()) {
1414+
if (isConst) {
14121415
passedByValueError(var, inconclusive, isRangeBasedFor);
14131416
continue;
14141417
}

test/testother.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,8 +2435,10 @@ class TestOther : public TestFixture {
24352435
ASSERT_EQUALS("", errout_str());
24362436

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

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

0 commit comments

Comments
 (0)