Skip to content

Commit 569f3d6

Browse files
Fix #14952 Stack overflow in ValueFlow::isLifetimeBorrowed() (#8770)
1 parent 933246d commit 569f3d6

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/token.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,7 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool poi
24332433
varTok = varTok->next();
24342434
while (Token::Match(varTok, "%name% ::"))
24352435
varTok = varTok->tokAt(2);
2436+
assert(varTok != tok);
24362437
std::pair<const Token*, const Token*> r = typeDecl(varTok);
24372438
if (r.first)
24382439
return r;

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger &errorLogger, co
31463146
valueFlowLifetimeConstructor(tok->next(), tokenlist, errorLogger, settings);
31473147
}
31483148
// Check function calls
3149-
else if (Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) {
3149+
else if (tok->scope()->isExecutable() && Token::Match(tok, "%name% (")) {
31503150
valueFlowLifetimeFunction(tok, tokenlist, errorLogger, settings);
31513151
}
31523152
// Unique pointer lifetimes

test/testvalueflow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8481,6 +8481,17 @@ class TestValueFlow : public TestFixture {
84818481
" auto b = a;\n"
84828482
"}\n";
84838483
(void)valueOfTok(code, "b");
8484+
8485+
code = "namespace O {}\n" // #14952
8486+
"namespace N {\n"
8487+
" using namespace O;\n"
8488+
" enum class E { E0 };\n"
8489+
" auto E0 = E::E0;\n"
8490+
" struct S {\n"
8491+
" E f() const { return E0; }\n"
8492+
" };\n"
8493+
"}\n";
8494+
(void)valueOfTok(code, "E0");
84848495
}
84858496

84868497
void valueFlowHang() {

0 commit comments

Comments
 (0)