Fix #11091 FP: Using object that is a temporary (#4754)

This commit is contained in:
chrchr-github 2023-02-06 22:04:27 +01:00 committed by GitHub
parent d8323c367e
commit 4f915499d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -4417,7 +4417,7 @@ static const Function* findConstructor(const Scope* scope, const Token* tok, con
f = nullptr; f = nullptr;
std::vector<const Function*> candidates; std::vector<const Function*> candidates;
for (const Function& function : scope->functionList) { for (const Function& function : scope->functionList) {
if (function.argCount() != args.size()) if (function.minArgCount() > args.size())
continue; continue;
if (!function.isConstructor()) if (!function.isConstructor())
continue; continue;

View File

@ -33,7 +33,7 @@ private:
Settings settings; Settings settings;
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
void check_(const char* file, int line, const char code[], bool inconclusive = false, const char* filename = "test.cpp") { void check_(const char* file, int line, const char code[], bool inconclusive = true, const char* filename = "test.cpp") {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
@ -3675,21 +3675,16 @@ private:
} }
void danglingTemporaryLifetime() { void danglingTemporaryLifetime() {
check("struct MyClass\n" // FP - #11091 check("struct C {\n" // #11091
"{\n" " C(C& rhs);\n"
" MyClass(MyClass& rhs);\n" " explicit C(const S& n, const S& p = {});\n"
" explicit MyClass(const wxString& name, const wxString& path = {});\n" " bool f() const;\n"
" bool IsAnotherRunning() const;\n" " S m;\n"
" \n"
" wxString m_fn;\n"
"};\n" "};\n"
" \n" "void f() {\n"
"void bar()\n" " C c(\"\");\n"
"{\n" " while (c.f()) {}\n"
" MyClass mutex(\"\");\n" "}\n");
" while (mutex.IsAnotherRunning())\n"
" DoSomething();\n"
"}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("const int& g(const int& x) {\n" check("const int& g(const int& x) {\n"