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;
std::vector<const Function*> candidates;
for (const Function& function : scope->functionList) {
if (function.argCount() != args.size())
if (function.minArgCount() > args.size())
continue;
if (!function.isConstructor())
continue;

View File

@ -33,7 +33,7 @@ private:
Settings settings;
#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..
errout.str("");
@ -3675,21 +3675,16 @@ private:
}
void danglingTemporaryLifetime() {
check("struct MyClass\n" // FP - #11091
"{\n"
" MyClass(MyClass& rhs);\n"
" explicit MyClass(const wxString& name, const wxString& path = {});\n"
" bool IsAnotherRunning() const;\n"
" \n"
" wxString m_fn;\n"
check("struct C {\n" // #11091
" C(C& rhs);\n"
" explicit C(const S& n, const S& p = {});\n"
" bool f() const;\n"
" S m;\n"
"};\n"
" \n"
"void bar()\n"
"{\n"
" MyClass mutex(\"\");\n"
" while (mutex.IsAnotherRunning())\n"
" DoSomething();\n"
"}");
"void f() {\n"
" C c(\"\");\n"
" while (c.f()) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("const int& g(const int& x) {\n"