Title
Holistic functional equivalence for function templates
Status
c++23
Section
13.7.7.2 [temp.over.link]
Submitter
Davis Herring

Created on 2022-06-20.00:00:00 last changed 16 months ago

Messages

Date: 2022-09-09.20:14:08

Proposed resolution (approved by CWG 2022-09-09):

  1. Append to 6.4.1 [basic.scope.scope] paragraph 3 as follows:

    • ...
    • the types of their object parameters are equivalent.
    Two function templates have corresponding signatures if their template-parameter-lists have the same length, corresponding template-parameters are equivalent, they have equivalent non-object-parameter-type-lists and return types (if any), and, if both are non-static members, they have corresponding object parameters.

  2. Change in 6.4.1 [basic.scope.scope] paragraph 4 as follows:

    • ...
      • ...
      • both declare function templates with corresponding signatures and equivalent non-object-parameter-type-lists, return types (if any), template-heads, and trailing requires-clauses (if any), and, if both are non-static members, they have corresponding object parameters.
  3. Change in 13.7.7.2 [temp.over.link] paragraph 7 as follows:

    If the validity or meaning of the program depends on whether two constructs are equivalent, and they are functionally equivalent but not equivalent, the program is ill-formed, no diagnostic required. Furthermore, if two function templates that do not correspond
    • have the same name,
    • have corresponding signatures (6.4.1 [basic.scope.scope]),
    • would declare the same entity (6.6 [basic.link]) considering them to correspond, and
    • accept and are satisfied by the same set of template argument lists,
    the program is ill-formed, no diagnostic required.
Date: 2022-08-15.00:00:00

Suggested resolution (August, 2022) [SUPERSEDED]:

  1. Append to 6.4.1 [basic.scope.scope] paragraph 3 as follows:

    • ...
    • the types of their object parameters are equivalent.
    Two function templates have corresponding signatures if their template-parameter-lists have the same length, corresponding template-parameters are equivalent, they have equivalent non-object-parameter-type-lists and return types (if any), and, if both are non-static members, they have corresponding object parameters.

  2. Change in 6.4.1 [basic.scope.scope] paragraph 4 as follows:

    • ...
      • ...
      • both declare function templates with corresponding signatures and equivalent non-object-parameter-type-lists, return types (if any), template-heads, and trailing requires-clauses (if any), and, if both are non-static members, they have corresponding object parameters.
  3. Change in 13.7.7.2 [temp.over.link] paragraph 7 as follows:

    If the validity or meaning of the program depends on whether two constructs are equivalent, and they are functionally equivalent but not equivalent, the program is ill-formed, no diagnostic required. Furthermore, if two function templates with corresponding signatures do not correspond, but accept and are satisfied by the same set of template argument lists, the program is ill-formed, no diagnostic required.
Date: 2022-08-27.06:13:26

Suggested resolution [SUPERSEDED]:

Change in 13.7.7.2 [temp.over.link] paragraph 7 as follows:

If the validity or meaning of the program depends on whether two constructs are equivalent, and they are functionally equivalent but not equivalent, the program is ill-formed, no diagnostic required. Furthermore, if two function templates do not correspond, but accept and are satisfied by the same set of template argument lists, the program is ill-formed, no diagnostic required.
Date: 2022-11-15.00:00:00

[Accepted as a DR at the November, 2022 meeting.]

In C++20, 13.7.7.2 [temp.over.link] paragraph 7 defined equivalence for function templates in terms of equivalence of several of its components; functional equivalence for them was similar in that it was defined recursively for their "return types and parameter lists", but differed with regard to constraints in that it required that they "accept and are satisfied by the same set of template argument lists". P1787R6 simplified the treatment by relying entirely on the "depends on whether two constructs are equivalent, and they are functionally equivalent but not equivalent" rule to make the correspondence check between the function templates ill-formed, no diagnostic required.

This created a situation where moving a constraint between a template-head and a requires-clause makes a function template truly different (because there is no reasonable way to read 6.4.1 [basic.scope.scope] bullet 4.3.2's "equivalent [...], template-heads, and trailing requires-clauses (if any)" as requiring a joint check for functional equivalence), even if overload resolution would never be able to distinguish them.

History
Date User Action Args
2023-07-16 13:00:43adminsetstatus: open -> c++23
2023-07-16 13:00:43adminsetstatus: drwp -> open
2023-02-18 18:43:04adminsetstatus: dr -> drwp
2022-11-25 05:14:04adminsetstatus: ready -> dr
2022-09-09 20:14:08adminsetstatus: drafting -> ready
2022-08-27 06:13:26adminsetmessages: + msg6912
2022-08-26 21:45:07adminsetmessages: + msg6908
2022-08-19 07:54:33adminsetstatus: open -> drafting
2022-06-23 22:39:13adminsetmessages: + msg6865
2022-06-20 00:00:00admincreate