From: Marek Polacek Date: Thu, 29 Oct 2020 19:08:31 +0000 (-0400) Subject: c++: Disable -Winit-list-lifetime in unevaluated operand [PR97632] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f620e64a6f13371b95be5b17abba0acf15bf7cae;p=gcc.git c++: Disable -Winit-list-lifetime in unevaluated operand [PR97632] Jon suggested turning this warning off when we're not actually evaluating the operand. This patch does that. gcc/cp/ChangeLog: PR c++/97632 * init.c (build_new_1): Disable -Winit-list-lifetime for an unevaluated operand. gcc/testsuite/ChangeLog: PR c++/97632 * g++.dg/warn/Winit-list4.C: New test. --- diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 1bddb6555dc..ffb84ea5b09 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2957,7 +2957,7 @@ build_new_1 (vec **placement, tree type, tree nelts, return error_mark_node; } - if (is_std_init_list (elt_type)) + if (is_std_init_list (elt_type) && !cp_unevaluated_operand) warning (OPT_Winit_list_lifetime, "% of % does not " "extend the lifetime of the underlying array"); diff --git a/gcc/testsuite/g++.dg/warn/Winit-list4.C b/gcc/testsuite/g++.dg/warn/Winit-list4.C new file mode 100644 index 00000000000..d136187e2c6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Winit-list4.C @@ -0,0 +1,15 @@ +// PR c++/97632 +// { dg-do compile { target c++20 } } +// Test we don't warn in an unevaluated operand. + +#include + +template +concept default_initializable + = requires + { + _Tp{}; + (void) ::new _Tp; // { dg-bogus "does not extend the lifetime" } + }; + +static_assert(default_initializable>);