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"