return ret;
}
+/* Returns true if FN has two parameters, of which the second has type
+ size_t. */
+
+static bool
+second_parm_is_size_t (tree fn)
+{
+ tree t = FUNCTION_ARG_CHAIN (fn);
+ return (t
+ && same_type_p (TREE_VALUE (t), size_type_node)
+ && TREE_CHAIN (t) == void_list_node);
+}
+
/* Returns true iff T, an element of an OVERLOAD chain, is a usual
deallocation function (3.7.4.2 [basic.stc.dynamic.deallocation]). */
of which has type std::size_t (18.2), then this function is a usual
deallocation function. */
bool global = DECL_NAMESPACE_SCOPE_P (t);
- t = FUNCTION_ARG_CHAIN (t);
- if (t == void_list_node
- || (t && same_type_p (TREE_VALUE (t), size_type_node)
- && (!global || flag_sized_deallocation)
- && TREE_CHAIN (t) == void_list_node))
+ if (FUNCTION_ARG_CHAIN (t) == void_list_node
+ || ((!global || flag_sized_deallocation)
+ && second_parm_is_size_t (t)))
return true;
return false;
}
function (3.7.4.2) and that function, considered as a placement
deallocation function, would have been selected as a match for the
allocation function, the program is ill-formed." */
- if (non_placement_deallocation_fn_p (fn))
+ if (second_parm_is_size_t (fn))
{
+ const char *msg1
+ = G_("exception cleanup for this placement new selects "
+ "non-placement operator delete");
+ const char *msg2
+ = G_("%q+D is a usual (non-placement) deallocation "
+ "function in C++14 (or with -fsized-deallocation)");
+
/* But if the class has an operator delete (void *), then that is
the usual deallocation function, so we shouldn't complain
about using the operator delete (void *, size_t). */
- for (t = BASELINK_P (fns) ? BASELINK_FUNCTIONS (fns) : fns;
- t; t = OVL_NEXT (t))
+ if (DECL_CLASS_SCOPE_P (fn))
+ for (t = BASELINK_P (fns) ? BASELINK_FUNCTIONS (fns) : fns;
+ t; t = OVL_NEXT (t))
+ {
+ tree elt = OVL_CURRENT (t);
+ if (non_placement_deallocation_fn_p (elt)
+ && FUNCTION_ARG_CHAIN (elt) == void_list_node)
+ goto ok;
+ }
+ /* Before C++14 a two-parameter global deallocation function is
+ always a placement deallocation function, but warn if
+ -Wc++14-compat. */
+ else if (!flag_sized_deallocation)
{
- tree elt = OVL_CURRENT (t);
- if (non_placement_deallocation_fn_p (elt)
- && FUNCTION_ARG_CHAIN (elt) == void_list_node)
- goto ok;
+ if ((complain & tf_warning)
+ && warning (OPT_Wc__14_compat, msg1))
+ inform (0, msg2, fn);
+ goto ok;
}
- if (complain & tf_error)
+
+ if (complain & tf_warning_or_error)
{
- permerror (0, "non-placement deallocation function %q+D", fn);
- permerror (input_location, "selected for placement delete");
+ if (permerror (input_location, msg1))
+ {
+ /* Only mention C++14 for namespace-scope delete. */
+ if (DECL_NAMESPACE_SCOPE_P (fn))
+ inform (0, msg2, fn);
+ else
+ inform (0, "%q+D is a usual (non-placement) deallocation "
+ "function", fn);
+ }
}
else
return error_mark_node;
-// Test that -Wc++14-compat warns about the change in meaning.
-// { dg-options "-Wall" }
+// Test for a diagnostic about a usual deallocation function used as a
+// placement deallocation function. This will be a warning in C++98/11
+// modes and an error in C++14 mode.
-typedef __SIZE_TYPE__ size_t;
-void operator delete[] (void *p, size_t s) throw(); // { dg-warning "usual" "" { target { ! c++14 } } }
+// { dg-options "-Wc++14-compat" }
+
+#include <new>
+void *operator new (std::size_t s, std::size_t)
+{
+ return operator new (s);
+}
+
+void operator delete (void *p, std::size_t) throw()
+{
+ return ::operator delete (p);
+}
+
+struct A
+{
+ A();
+};
+
+void f()
+{
+ new (42) A; // { dg-message "" }
+}