aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/init.c2
-rw-r--r--gcc/testsuite/g++.dg/warn/Winit-list4.C15
2 files changed, 16 insertions, 1 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 1bddb655..ffb84ea 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2957,7 +2957,7 @@ build_new_1 (vec<tree, va_gc> **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,
"%<new%> of %<initializer_list%> 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 0000000..d136187
--- /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 <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>>);