#11472 FP returnTempReference with cast and scope operator (#4676)

This commit is contained in:
chrchr-github 2023-01-02 22:13:56 +01:00 committed by GitHub
parent 48a0d934a3
commit 4c1c506d21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -5010,7 +5010,7 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty
// find start of qualified function name
const Token *tok1 = typeTok;
while (Token::Match(tok1->tokAt(-2), "%type% ::") ||
while ((Token::Match(tok1->tokAt(-2), "%type% ::") && !tok1->tokAt(-2)->isKeyword()) ||
(Token::simpleMatch(tok1->tokAt(-2), "> ::") && tok1->linkAt(-2) && Token::Match(tok1->linkAt(-2)->tokAt(-1), "%type%"))) {
if (tok1->strAt(-1) == "::")
tok1 = tok1->tokAt(-2);

View File

@ -3750,6 +3750,16 @@ private:
"}\n",
true);
ASSERT_EQUALS("", errout.str());
// #11472
check("namespace N {\n"
" struct T { int m; };\n"
" int i;\n"
" const T& f(const T* p) {\n"
" return p != nullptr ? *p : *reinterpret_cast<const ::N::T*>(&i);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeBorrowedMembers()