Fix #11995 FP passedByValue when variable is moved from (#5455)

This commit is contained in:
chrchr-github 2023-09-17 22:32:35 +02:00 committed by GitHub
parent 0c51977f86
commit 640b561633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -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;

View File

@ -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",