From 5c7914aaa6ea35f9789466799d89cd9363af366c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 21 Apr 2023 20:33:06 +0200 Subject: [PATCH] Fix FN constParameterReference with std::array (#4999) --- lib/checkother.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 37f23d417..08d22e673 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1424,7 +1424,7 @@ void CheckOther::checkConstVariable() continue; if (var->isStatic()) continue; - if (var->isArray()) + if (var->isArray() && !var->isStlType()) continue; if (var->isEnumType()) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 320279ff6..1530a3a36 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3107,6 +3107,14 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(std::array& a) {\n" + " if (a[0]) {}\n" + "}\n" + "void g(std::array& a) {\n" + " a.fill(0);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'a' can be declared as const array\n", errout.str()); } void constParameterCallback() {