On 9/21/26 12:57 PM, Jakub Jelinek wrote:
On Mon, Sep 21, 2026 at 11:32:21AM -0400, Jason Merrill wrote:
+                 tree arg;
+                 unsigned ia;
+                 nargs = list_length (t) + 1;
+                 args = XALLOCAVEC (tree, nargs);
+                 args[0] = ptr_type_node;
+                 for (arg = t, ia = 1; arg != NULL_TREE;
+                      arg = TREE_CHAIN (arg), ++ia)
+                   args[ia] = TREE_VALUE (arg);

"as specified below" refers to https://eel.is/c++draft/expr.new#32
so instead of filling args with the parameter types from alloc_fn, we should
use the same actual arguments that are used for the call later in the
function.

So like this then?

2026-09-21  Jakub Jelinek  <[email protected]>

        P3769R1
        PR c++/125848
        * call.cc (build_op_delete_call_1): Implement C++26
        P3769R1 - Clarification of placement new deallocation.  Instead of
        calling instantiate_type to select placement deallocation function
        iterate over OVERLOAD if any, perform argument deduction for
        templates, ignore candidates with different parameter type lists
        or unsatisfied constraints and if only one candidate remains,
        use it, otherwise don't destruct on throw.

        * g++.dg/cpp26/placement-new1.C: New test.

--- a/gcc/cp/call.cc    2026-09-16 22:17:02.640462648 +0200
+++ b/gcc/cp/call.cc    2026-09-21 18:52:59.556721249 +0200
@@ -8127,28 +8127,67 @@ build_op_delete_call_1 (enum tree_code c
if (placement)
      {
-      /* "A declaration of a placement deallocation function matches the
-        declaration of a placement allocation function if it has the same
-        number of parameters and, after parameter transformations (8.3.5),
-        all parameter types except the first are identical."
+      /* For a placement allocation function, the matching deallocation
+        function is selected as follows:
- So we build up the function type we want and ask instantiate_type
-        to get it for us.  */
+        - Each candidate that is a function template is replaced by the
+          function template specializations (if any) generated using template
+          argument deduction with arguments as specified below.
+        - Each candidate whose parameter-type-list is not identical to that
+          of the allocation function, ignoring their respective first
+          parameters, is removed from the set of candidates.
+        - Each candidate whose associated constraints (if any) are not
+          satisfied is removed from the set of candidates.
+        - If exactly one function remains, that function is selected.
+        - Otherwise, no deallocation function is selected.  */
        t = FUNCTION_ARG_CHAIN (alloc_fn);
-      t = tree_cons (NULL_TREE, ptr_type_node, t);
-      t = build_function_type (void_type_node, t);
+      fn = NULL_TREE;
+      tree *args = NULL;
+      unsigned nargs = 0;
+      for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
+       {
+         if (TREE_CODE (elt) == TEMPLATE_DECL)
+           {
+             tree targs = make_tree_vec (DECL_NTPARMS (elt));
+             if (args == NULL)
+               {
+                 nargs = call_expr_nargs (placement) + 1;
+                 args = XALLOCAVEC (tree, nargs);
+                 args[0] = TREE_TYPE (addr);
+                 for (unsigned i = 1; i < nargs - 1; ++i)
+                   args[i] = TREE_TYPE (CALL_EXPR_ARG (placement, i));
+                 args[nargs - 1] = void_type_node;
+               }
+             elt = fn_type_unification (elt, NULL_TREE, targs, args,
+                                        nargs, void_type_node,
+                                        DEDUCE_EXACT, LOOKUP_NORMAL,

This is still doing [temp.deduct.type] deduction rather than [temp.deduct.call] as specified.

That is, we should fill args with the actual args rather than their types, use DEDUCE_CALL, and not pass a return type.

Jason

Reply via email to