Fix #11465 FP returnDanglingLifetime/returnTempreference with typeid (#4675)

This commit is contained in:
chrchr-github 2023-01-02 17:46:03 +01:00 committed by GitHub
parent f793b7dd35
commit 2007cd0a1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -413,6 +413,8 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
} }
if (Token::simpleMatch(tok, "(") && tok->astOperand1() && if (Token::simpleMatch(tok, "(") && tok->astOperand1() &&
(tok->astOperand2() || Token::simpleMatch(tok->next(), ")"))) { (tok->astOperand2() || Token::simpleMatch(tok->next(), ")"))) {
if (Token::simpleMatch(tok->astOperand1(), "typeid"))
return false;
if (tok->valueType()) { if (tok->valueType()) {
return tok->valueType()->reference == Reference::None; return tok->valueType()->reference == Reference::None;
} }

View File

@ -78,6 +78,7 @@ private:
TEST_CASE(testautovar_return2); TEST_CASE(testautovar_return2);
TEST_CASE(testautovar_return3); TEST_CASE(testautovar_return3);
TEST_CASE(testautovar_return4); TEST_CASE(testautovar_return4);
TEST_CASE(testautovar_return5);
TEST_CASE(testautovar_extern); TEST_CASE(testautovar_extern);
TEST_CASE(testautovar_reassigned); TEST_CASE(testautovar_reassigned);
TEST_CASE(testinvaliddealloc); TEST_CASE(testinvaliddealloc);
@ -577,6 +578,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void testautovar_return5() { // #11465
check("struct S {};\n"
"const std::type_info* f() {\n"
" return &typeid(S);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void testautovar_extern() { void testautovar_extern() {
check("struct foo *f()\n" check("struct foo *f()\n"
"{\n" "{\n"