From 8fd0839fea033b5d2d3e96d55ee02906b68e5e7f Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 6 Apr 2020 09:02:10 -0500 Subject: [PATCH] Add regression test for 9534: False positive: Returning pointer to local variable 'x' that will be invalid when returning. (#2596) --- test/testautovariables.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 0fada3f5c..34f9b20b8 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2301,6 +2301,16 @@ private: " return fred.s.c_str();\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #9534 + check("struct A {\n" + " int* x;\n" + "};\n" + "int* f(int i, std::vector& v) {\n" + " A& y = v[i];\n" + " return &y.x[i];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void danglingLifetimeFunction() {