The [with T = $TYPE] diagnostic machinery must not cause recursion. So let's
not unilaterally warn about new alignment. (template extracted from Open3D.)
gcc/cp/
* init.c (build_new_1): Check complain before alignment warning.
gcc/testsuite/
* g++.dg/diagnostic/recur-align.C: New.
= (type_num_arguments (TREE_TYPE (alloc_fn)) > 1
|| varargs_function_p (alloc_fn));
- if (warn_aligned_new
+ if (complain & tf_warning_or_error
+ && warn_aligned_new
&& !placement_allocation_fn_p
&& TYPE_ALIGN (elt_type) > malloc_alignment ()
&& (warn_aligned_new > 1
--- /dev/null
+// ICE with diagnostic recursion
+// { dg-do compile { target { c++11_only || c++14_only } } }
+// { dg-options -Waligned-new }
+
+struct __attribute__ ((aligned(256))) Aligned
+{
+ int b;
+};
+
+template<typename T>
+auto Foo (const T* x) -> decltype (new T (*x))
+{
+ return new T (*x); // { dg-warning "with extended alignment" }
+}
+
+void Bar () {
+ Aligned y;
+ Foo (&y);
+}