Fix #11374 FP danglingTemporaryLifetime with std::string_view (#4602)

This commit is contained in:
chrchr-github 2022-11-27 09:22:55 +01:00 committed by GitHub
parent 52264b9c26
commit 4cb49013a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -2178,8 +2178,6 @@ T* getTokenArgumentFunctionImpl(T* tok, int& argn)
return nullptr;
if (Token::simpleMatch(argtok, ","))
argtok = argtok->astOperand1();
if (Token::simpleMatch(argtok, "(") && argtok->astOperand2())
argtok = argtok->astOperand2();
tok = argtok;
while (Token::Match(tok->astParent(), ",|(|{")) {
tok = tok->astParent();

View File

@ -326,6 +326,8 @@ private:
ASSERT(Result::True == isUsedAsBool("void f(bool b); void f() { int i; f(i); }","i )"));
ASSERT(Result::True == isUsedAsBool("void f() { int *i; if (*i) {} }", "i )"));
ASSERT(Result::True == isUsedAsBool("void f() { int *i; if (*i) {} }", "* i )"));
ASSERT(Result::True == isUsedAsBool("int g(); void h(bool); void f() { h(g()); }", "( ) )"));
ASSERT(Result::True == isUsedAsBool("int g(int); void h(bool); void f() { h(g(0)); }", "( 0 ) )"));
}
};

View File

@ -2749,6 +2749,14 @@ private:
" v.data();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n", errout.str());
check("std::string convert(std::string_view sv) { return std::string{ sv }; }\n" // #11374
"auto f() {\n"
" std::vector<std::string> v;\n"
" v.push_back(convert(\"foo\"));\n"
" return v[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeUniquePtr()