From 10c73fc75bb89c7466eb5a680a3db831b28e1d47 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 21 Jan 2026 16:24:30 +0100 Subject: [PATCH 1/2] Update valueflow.cpp --- lib/valueflow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 023d2ebde31..0695912c00c 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2700,7 +2700,8 @@ static void valueFlowLifetimeClassConstructor(Token* tok, if (isDesignatedInitializerArg) ls.argtok = ls.argtok->astOperand2(); const Variable &var = *it; - if (var.valueType() && var.valueType()->container && var.valueType()->container->stdStringLike && !var.valueType()->container->view) + if (ls.argtok->valueType() && ls.argtok->valueType()->pointer && + var.valueType() && var.valueType()->container && var.valueType()->container->stdStringLike && !var.valueType()->container->view) return; // TODO: check in isLifetimeBorrowed()? if (var.isReference() || var.isRValueReference()) { ls.byRef(tok, tokenlist, errorLogger, settings); From 4148183b3c685c3d75b22af50ec558d6e6cb6e31 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 21 Jan 2026 16:29:11 +0100 Subject: [PATCH 2/2] Update testautovariables.cpp --- test/testautovariables.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 2117fe7ba8d..1091a03e9ff 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3957,6 +3957,15 @@ class TestAutoVariables : public TestFixture { "[test.cpp:6:30] -> [test.cpp:6:30] -> [test.cpp:6:21] -> [test.cpp:5:21] -> [test.cpp:8:12]: (error) Returning object that points to local variable 'a' that will be invalid when returning. [returnDanglingLifetime]\n", errout_str()); + check("struct S { const std::string& r; };\n" // #14209 + "S f() {\n" + " std::string s;\n" + " return S{ s };\n" + "}\n"); + ASSERT_EQUALS( + "[test.cpp:4:15] -> [test.cpp:3:17] -> [test.cpp:4:13]: (error) Returning object that points to local variable 's' that will be invalid when returning. [returnDanglingLifetime]\n", + errout_str()); + check("struct A { int& x; };\n" // #14247 "A f() {\n" " int x = 0;\n"