Add regression test for 9534: False positive: Returning pointer to local variable 'x' that will be invalid when returning. (#2596)

This commit is contained in:
Paul Fultz II 2020-04-06 09:02:10 -05:00 committed by GitHub
parent 8dd0a9241c
commit 8fd0839fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -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<A>& v) {\n"
" A& y = v[i];\n"
" return &y.x[i];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeFunction() {