diff --git a/lib/token.cpp b/lib/token.cpp index d8b438c5073..eac69decee7 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2433,6 +2433,7 @@ std::pair Token::typeDecl(const Token* tok, bool poi varTok = varTok->next(); while (Token::Match(varTok, "%name% ::")) varTok = varTok->tokAt(2); + assert(varTok != tok); std::pair r = typeDecl(varTok); if (r.first) return r; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 63543e1a8f5..da49c78e709 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3142,7 +3142,7 @@ static void valueFlowLifetime(TokenList &tokenlist, ErrorLogger &errorLogger, co valueFlowLifetimeConstructor(tok->next(), tokenlist, errorLogger, settings); } // Check function calls - else if (Token::Match(tok, "%name% (") && !Token::simpleMatch(tok->linkAt(1), ") {")) { + else if (tok->scope()->isExecutable() && Token::Match(tok, "%name% (")) { valueFlowLifetimeFunction(tok, tokenlist, errorLogger, settings); } // Unique pointer lifetimes diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c98680b8180..72e115cfe2b 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -8355,6 +8355,17 @@ class TestValueFlow : public TestFixture { " auto b = a;\n" "}\n"; (void)valueOfTok(code, "b"); + + code = "namespace O {}\n" // #14952 + "namespace N {\n" + " using namespace O;\n" + " enum class E { E0 };\n" + " auto E0 = E::E0;\n" + " struct S {\n" + " E f() const { return E0; }\n" + " };\n" + "}\n"; + (void)valueOfTok(code, "E0"); } void valueFlowHang() {