diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 964690e62..98bc716f4 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2050,6 +2050,9 @@ T* getTokenArgumentFunctionImpl(T* tok, int& argn) tok = tok->link()->previous(); if (!Token::Match(tok, "%name%|(|{")) return nullptr; + // Skip labels + if (Token::Match(tok, "%name% :")) + return nullptr; return tok; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 291b6fdf6..648653f7f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6614,6 +6614,14 @@ private: " }\n" "}\n"; valueOfTok(code, "age"); + + code = "void a() {\n" + " struct b {\n" + " int d;\n" + " };\n" + " for (b c : {b{}, {}}) {}\n" + "}\n"; + valueOfTok(code, "c"); } void valueFlowHang() {