Created on 2023-09-15.00:00:00 last changed 6 months ago
CWG 2023-10-06
CWG raised the question to EWG whether the special rule that allows the example in this issue for backward compatibility should be extended to member functions with explicit object parameters. This is tracked via paper issue 1645.
EWG 2024-03-18
EWG has no consensus to extend the rules to explicit object parameters.
Possible resolution:
Change and split in 6.4.1 [basic.scope.scope] paragraph 3 as follows:
...
Two functions have corresponding non-object signatures if they have the same non-object-parameter-type-list. Two function templates have corresponding non-object signatures if their template-parameter-lists have the same length, their corresponding template-parameter s are equivalent, and 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. Two functions or function templates have corresponding signatures if they have corresponding non-object signatures and, if both are non-static members, they have corresponding object parameters.
Change in 6.4.1 [basic.scope.scope] paragraph 4 as follows:
Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unlessTwo function or function template declarations declare corresponding overloads if:
- either is a using-declarator , or
- one declares a type (not a typedef-name) and the other declares a variable, non-static data member other than of an anonymous union (11.5.2 [class.union.anon]), enumerator, function, or function template, or
- each declares a function or function template and they do not declare corresponding overloads.
- both declare functions with
the same non-object-parameter-type-list, equivalent (13.7.7.2 [temp.over.link]) trailing requires-clauses (if any, except as specified in 13.7.5 [temp.friend]), and, if both are non-static members, they have corresponding object parameters,corresponding signatures or both declare function templates with corresponding signatures andequivalent template-heads and trailing requires-clauses (if any).- both have equivalent (13.7.7.2 [temp.over.link]) template-heads and trailing requires-clauses (if any, except as specified in 13.7.5 [temp.friend]).
Change in 12.2.2.3 [over.match.oper] paragraph 4 as follows:
A non-template function or function template F named operator== is a rewrite target with first operand o unless a search for the name operator!= in the scope S from the instantiation context of the operator expression finds a function or function template F2 such thatwould correspondF2 is an implicit object member function and F and F2 have corresponding non-object signatures (6.4.1 [basic.scope.scope])to F if its name were operator==, where S is the scope of the class type of o if F is a class member, and the namespace scope of which F is a member otherwise. A function template specialization named operator== is a rewrite target if its function template is a rewrite target.
Subclause 12.2.2.3 [over.match.oper] paragraph 4 specifies:
A non-template function or function template F named operator== is a rewrite target with first operand o unless a search for the name operator!= in the scope S from the instantiation context of the operator expression finds a function or function template that would correspond (6.4.1 [basic.scope.scope]) to F if its name were operator==, where S is the scope of the class type of o if F is a class member, and the namespace scope of which F is a member otherwise. A function template specialization named operator== is a rewrite target if its function template is a rewrite target.
The meaning of "corresponds" has changed with paper P0847 such that this example from the Working Paper is now ill-formed:
struct B { bool operator==(const B&); }; struct C : B { C(); C(B); bool operator!=(const B&); }; bool c1 = B() == C(); // was OK, now ill-formed
The reason is that the definition of "corresponds" now also considers the object parameters, which are different in the example above.
Possible resolution [SUPERSEDED]:
Change and split in 6.4.1 [basic.scope.scope] paragraph 3 as follows:
...
Two functions have corresponding non-object signatures if they have the same non-object-parameter-type-list. Two function templates have corresponding non-object signatures if their template-parameter-lists have the same length, their corresponding template-parameter s are equivalent, and 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. Two functions or function templates have corresponding signatures if they have corresponding non-object signatures and, if both are non-static members, they have corresponding object parameters.
Change in 6.4.1 [basic.scope.scope] paragraph 4 as follows:
Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unlessTwo function or function template declarations declare corresponding overloads if:
- either is a using-declarator , or
- one declares a type (not a typedef-name) and the other declares a variable, non-static data member other than of an anonymous union (11.5.2 [class.union.anon]), enumerator, function, or function template, or
- each declares a function or function template and they do not declare corresponding overloads.
- both declare functions with
the same non-object-parameter-type-list, equivalent (13.7.7.2 [temp.over.link]) trailing requires-clauses (if any, except as specified in 13.7.5 [temp.friend]), and, if both are non-static members, they have corresponding object parameters,corresponding signatures or both declare function templates with corresponding signatures andequivalent template-heads and trailing requires-clauses (if any).- both have equivalent (13.7.7.2 [temp.over.link]) template-heads and trailing requires-clauses (if any, except as specified in 13.7.5 [temp.friend]).
Change in 12.2.2.3 [over.match.oper] paragraph 4 as follows:
A non-template function or function template F named operator== is a rewrite target with first operand o unless a search for the name operator!= in the scope S from the instantiation context of the operator expression finds a function or function template F2 such thatwould correspondF and F2 have corresponding non-object signatures (6.4.1 [basic.scope.scope])to F if its name were operator==, where S is the scope of the class type of o if F is a class member, and the namespace scope of which F is a member otherwise. A function template specialization named operator== is a rewrite target if its function template is a rewrite target.
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-03-18 12:50:42 | admin | set | status: open -> review |
2023-10-06 22:55:13 | admin | set | messages: + msg7451 |
2023-09-15 00:00:00 | admin | create |