Skip to content

Commit 4c1c506

Browse files
#11472 FP returnTempReference with cast and scope operator (#4676)
1 parent 48a0d93 commit 4c1c506

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5010,7 +5010,7 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty
50105010
// find start of qualified function name
50115011
const Token *tok1 = typeTok;
50125012

5013-
while (Token::Match(tok1->tokAt(-2), "%type% ::") ||
5013+
while ((Token::Match(tok1->tokAt(-2), "%type% ::") && !tok1->tokAt(-2)->isKeyword()) ||
50145014
(Token::simpleMatch(tok1->tokAt(-2), "> ::") && tok1->linkAt(-2) && Token::Match(tok1->linkAt(-2)->tokAt(-1), "%type%"))) {
50155015
if (tok1->strAt(-1) == "::")
50165016
tok1 = tok1->tokAt(-2);

test/testautovariables.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,16 @@ class TestAutoVariables : public TestFixture {
37503750
"}\n",
37513751
true);
37523752
ASSERT_EQUALS("", errout.str());
3753+
3754+
// #11472
3755+
check("namespace N {\n"
3756+
" struct T { int m; };\n"
3757+
" int i;\n"
3758+
" const T& f(const T* p) {\n"
3759+
" return p != nullptr ? *p : *reinterpret_cast<const ::N::T*>(&i);\n"
3760+
" }\n"
3761+
"}\n");
3762+
ASSERT_EQUALS("", errout.str());
37533763
}
37543764

37553765
void danglingLifetimeBorrowedMembers()

0 commit comments

Comments
 (0)