Skip to content

Commit 2007cd0

Browse files
Fix #11465 FP returnDanglingLifetime/returnTempreference with typeid (#4675)
1 parent f793b7d commit 2007cd0

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/astutils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
413413
}
414414
if (Token::simpleMatch(tok, "(") && tok->astOperand1() &&
415415
(tok->astOperand2() || Token::simpleMatch(tok->next(), ")"))) {
416+
if (Token::simpleMatch(tok->astOperand1(), "typeid"))
417+
return false;
416418
if (tok->valueType()) {
417419
return tok->valueType()->reference == Reference::None;
418420
}

test/testautovariables.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class TestAutoVariables : public TestFixture {
7878
TEST_CASE(testautovar_return2);
7979
TEST_CASE(testautovar_return3);
8080
TEST_CASE(testautovar_return4);
81+
TEST_CASE(testautovar_return5);
8182
TEST_CASE(testautovar_extern);
8283
TEST_CASE(testautovar_reassigned);
8384
TEST_CASE(testinvaliddealloc);
@@ -577,6 +578,14 @@ class TestAutoVariables : public TestFixture {
577578
ASSERT_EQUALS("", errout.str());
578579
}
579580

581+
void testautovar_return5() { // #11465
582+
check("struct S {};\n"
583+
"const std::type_info* f() {\n"
584+
" return &typeid(S);\n"
585+
"}\n");
586+
ASSERT_EQUALS("", errout.str());
587+
}
588+
580589
void testautovar_extern() {
581590
check("struct foo *f()\n"
582591
"{\n"

0 commit comments

Comments
 (0)