From 640b561633cd0c368c5355c43ba8d8c6cecfdc80 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 17 Sep 2023 22:32:35 +0200 Subject: [PATCH] Fix #11995 FP passedByValue when variable is moved from (#5455) --- lib/checkother.cpp | 8 +++++++- test/testother.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fb384ab5d..f2ea621ec 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1244,7 +1244,13 @@ static bool canBeConst(const Variable *var, const Settings* settings) const Function* func_scope = var->scope()->function; if (func_scope && func_scope->type == Function::Type::eConstructor) { //could be initialized in initializer list - if (func_scope->arg->link()->next()->str() == ":") { + const Token* init = func_scope->arg->link()->next(); + if (init->str() == "noexcept") { + init = init->next(); + if (init->link()) + init = init->link()->next(); + } + if (init->str() == ":") { for (const Token* tok2 = func_scope->arg->link()->next()->next(); tok2 != var->scope()->bodyStart; tok2 = tok2->next()) { if (tok2->varId() != var->declarationId()) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 0df3b2324..4c807e298 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2150,6 +2150,18 @@ private: "[test.cpp:18]: (performance) Function parameter 'v' should be passed by const reference.\n", errout.str()); + check("struct S {\n" // #11995 + " explicit S(std::string s) noexcept;\n" + " std::string m;\n" + "};\n" + "S::S(std::string s) noexcept : m(std::move(s)) {}\n" + "struct T {\n" + " explicit S(std::string s) noexcept(true);\n" + " std::string m;\n" + "};\n" + "T::T(std::string s) noexcept(true) : m(std::move(s)) {}\n"); + ASSERT_EQUALS("", errout.str()); + Settings settings1 = settingsBuilder().platform(cppcheck::Platform::Type::Win64).build(); check("using ui64 = unsigned __int64;\n" "ui64 Test(ui64 one, ui64 two) { return one + two; }\n",