From 1e79d8b96d26184d65b5d5fbe61a1012e216cd6b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 24 Nov 2024 00:13:00 +0100 Subject: [PATCH] Fix #13052 FP passedByValue for array of vectors (reopened) (#7005) --- lib/checkother.cpp | 5 ++++- test/testother.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 155464d5aab..36d7c76acee 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; } diff --git a/test/testother.cpp b/test/testother.cpp index 4dfb00ac03b..1a4d10c4f16 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2435,8 +2435,10 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("void f(const std::vector v[2]);\n" // #13052 - "int g(const std::array, 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 v[2]);\n" + "void g(const std::vector v[2]) {}\n" + "int h(const std::array, 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"