From f620e64a6f13371b95be5b17abba0acf15bf7cae Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 29 Oct 2020 15:08:31 -0400 Subject: [PATCH] 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. --- gcc/cp/init.c | 2 +- gcc/testsuite/g++.dg/warn/Winit-list4.C | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Winit-list4.C 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>); -- 2.30.2