Skip to content

Commit

Permalink
Fix #11995 FP passedByValue when variable is moved from (#5455)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 17, 2023
1 parent 0c51977 commit 640b561
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,18 @@ class TestOther : public TestFixture {
"[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",
Expand Down

0 comments on commit 640b561

Please sign in to comment.