diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 85cddb481..48d307ff2 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3189,6 +3189,7 @@ static void valueFlowLifetimeConstructor(Token *tok, TokenList *tokenlist, Error } else { ls.byVal(tok, tokenlist, errorLogger, settings); } + i++; } } } else if (Token::simpleMatch(tok, "{") && (astIsContainer(tok->astParent()) || astIsPointer(tok->astParent()))) { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 6319b1543..ea3635e77 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -1966,6 +1966,13 @@ private: " return A{x, x};\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct A { int i; const int& j; };\n" + "A f(int& x) {\n" + " int y = 0;\n" + " return A{y, x};\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void danglingLifetimeInitList() {