diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index ade6e335da7b18c5fe5d879e18fd87264b7420eb..aece89a3e9bdf8c20de384c6cee0457e0f2c4b33 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -7154,8 +7154,10 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) gimplify_and_add (init, &init_pre_p); /* Add a clobber for the temporary going out of scope, like - gimplify_bind_expr. */ + gimplify_bind_expr. But only if we did not promote the + temporary to static storage. */ if (gimplify_ctxp->in_cleanup_point_expr + && !TREE_STATIC (temp) && needs_to_live_in_memory (temp)) { if (flag_stack_reuse == SR_ALL) diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-pointer-pr110055.C b/gcc/testsuite/g++.dg/warn/Wdangling-pointer-pr110055.C new file mode 100644 index 0000000000000000000000000000000000000000..77dbbf380b691994d224d6f812a0f0eef92b710a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdangling-pointer-pr110055.C @@ -0,0 +1,16 @@ +// { dg-do compile } +// { dg-require-effective-target c++11 } +// { dg-options "-O3 -fno-exceptions -Wdangling-pointer" } + +#include <cstdint> +#include <vector> + +struct Data { + std::vector<uint16_t> v = {1, 1}; +}; + +int main() +{ + Data a; + Data b; +}