Skip to content

Commit 4f91549

Browse files
Fix #11091 FP: Using object that is a temporary (#4754)
1 parent d8323c3 commit 4f91549

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,7 @@ static const Function* findConstructor(const Scope* scope, const Token* tok, con
44174417
f = nullptr;
44184418
std::vector<const Function*> candidates;
44194419
for (const Function& function : scope->functionList) {
4420-
if (function.argCount() != args.size())
4420+
if (function.minArgCount() > args.size())
44214421
continue;
44224422
if (!function.isConstructor())
44234423
continue;

test/testautovariables.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestAutoVariables : public TestFixture {
3333
Settings settings;
3434

3535
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
36-
void check_(const char* file, int line, const char code[], bool inconclusive = false, const char* filename = "test.cpp") {
36+
void check_(const char* file, int line, const char code[], bool inconclusive = true, const char* filename = "test.cpp") {
3737
// Clear the error buffer..
3838
errout.str("");
3939

@@ -3675,21 +3675,16 @@ class TestAutoVariables : public TestFixture {
36753675
}
36763676

36773677
void danglingTemporaryLifetime() {
3678-
check("struct MyClass\n" // FP - #11091
3679-
"{\n"
3680-
" MyClass(MyClass& rhs);\n"
3681-
" explicit MyClass(const wxString& name, const wxString& path = {});\n"
3682-
" bool IsAnotherRunning() const;\n"
3683-
" \n"
3684-
" wxString m_fn;\n"
3678+
check("struct C {\n" // #11091
3679+
" C(C& rhs);\n"
3680+
" explicit C(const S& n, const S& p = {});\n"
3681+
" bool f() const;\n"
3682+
" S m;\n"
36853683
"};\n"
3686-
" \n"
3687-
"void bar()\n"
3688-
"{\n"
3689-
" MyClass mutex(\"\");\n"
3690-
" while (mutex.IsAnotherRunning())\n"
3691-
" DoSomething();\n"
3692-
"}");
3684+
"void f() {\n"
3685+
" C c(\"\");\n"
3686+
" while (c.f()) {}\n"
3687+
"}\n");
36933688
ASSERT_EQUALS("", errout.str());
36943689

36953690
check("const int& g(const int& x) {\n"

0 commit comments

Comments
 (0)