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.
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,
"%<new%> of %<initializer_list%> does not "
"extend the lifetime of the underlying array");
--- /dev/null
+// PR c++/97632
+// { dg-do compile { target c++20 } }
+// Test we don't warn in an unevaluated operand.
+
+#include <initializer_list>
+
+template<typename _Tp>
+concept default_initializable
+ = requires
+ {
+ _Tp{};
+ (void) ::new _Tp; // { dg-bogus "does not extend the lifetime" }
+ };
+
+static_assert(default_initializable<std::initializer_list<int>>);