From 2007cd0a1dbf0a9d76727a7c7ae977fc666a95d4 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 2 Jan 2023 17:46:03 +0100 Subject: [PATCH] Fix #11465 FP returnDanglingLifetime/returnTempreference with typeid (#4675) --- lib/astutils.cpp | 2 ++ test/testautovariables.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 531183568..c97dee32c 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -413,6 +413,8 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow } if (Token::simpleMatch(tok, "(") && tok->astOperand1() && (tok->astOperand2() || Token::simpleMatch(tok->next(), ")"))) { + if (Token::simpleMatch(tok->astOperand1(), "typeid")) + return false; if (tok->valueType()) { return tok->valueType()->reference == Reference::None; } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 3ddc8325b..904605364 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -78,6 +78,7 @@ private: TEST_CASE(testautovar_return2); TEST_CASE(testautovar_return3); TEST_CASE(testautovar_return4); + TEST_CASE(testautovar_return5); TEST_CASE(testautovar_extern); TEST_CASE(testautovar_reassigned); TEST_CASE(testinvaliddealloc); @@ -577,6 +578,14 @@ private: 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() { check("struct foo *f()\n" "{\n"