diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 72c3fbf588c..c1816af1a0f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3278,7 +3278,7 @@ static bool isDecayedPointer(const Token *tok) return true; if (!Token::simpleMatch(tok->astParent(), "return")) return false; - return astIsPointer(tok->astParent()); + return astIsPointer(tok->astParent()) || astIsContainerView(tok->astParent()); } static bool isConvertedToView(const Token* tok, const Settings& settings) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index e8d45157225..58bf423dadd 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3048,6 +3048,14 @@ class TestAutoVariables : public TestFixture { ASSERT_EQUALS( "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n", errout_str()); + + check("std::span f() {\n" // #12966 + " int a[10]{};\n" + " return a;\n" + "}\n"); + ASSERT_EQUALS( + "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'a' that will be invalid when returning.\n", + errout_str()); } void danglingLifetimeUniquePtr()