From 3f5054035de92c8949bb2eccb9192a4df98b439c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:52:58 +0100 Subject: [PATCH] Fix #11432 FP passedByValue for overriden function (#4632) --- lib/checkother.cpp | 2 +- test/testother.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 8a94ad892..6baaf1721 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1332,7 +1332,7 @@ void CheckOther::checkPassByReference() } // Check if variable could be const - if (!var->scope() || var->scope()->function->hasVirtualSpecifier()) + if (!var->scope() || var->scope()->function->isImplicitlyVirtual()) continue; if (canBeConst(var, mSettings)) { diff --git a/test/testother.cpp b/test/testother.cpp index 4c315320c..fc122b1e5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1970,6 +1970,15 @@ private: "int* f(U u) { return u.b; }\n"); ASSERT_EQUALS("", errout.str()); + check("struct B { virtual int f(std::string s) = 0; };\n" // #11432 + "struct D1 : B {\n" + " int f(std::string s) override { s += 'a'; return s.size(); }\n" + "}\n" + "struct D2 : B {\n" + " int f(std::string s) override { return s.size(); }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + Settings settings1; settings1.platform(Settings::Win64); check("using ui64 = unsigned __int64;\n"