Does that the current draft permit to form an overload set that consists of two non-static member declarations where one has ref-qualifier
Asked Answered
S

1

7

The basic.scope#scope-3.3.1 says

both declare functions with the same parameter-type-list, equivalent ([temp.over.link]) trailing requires-clauses (if any, except as specified in [temp.friend]), and, if both are non-static members, the same cv-qualifiers (if any) and ref-qualifier (if both have one)

The above rule could be understood to, For two non-static member functions with the same parameter-type-list, if anyone has a cv-qualifiers then both declarations should have the same cv-qualifiers; if both declarations have ref-qualifier, they should have the same ref-qualifier. Otherwise, they do not correspond.

struct A{
    void show();  //#1
    void show() const &;  //#2
};

In this snippet, Does #1 correspond to #2? Since #2 has a cv-qualifier but #1 does not have, even if the condition for having the same ref-qualifier is true, as per the rule(note the emphasized and in that rule), they do not correspond. So, Does it mean that the draft permits to form an overload set from such two declarations? After all, the section over.load#2.3 was removed by P1787.

Sihun answered 15/3, 2021 at 9:55 Comment(0)
E
1

This change was an inadvertent result of phrasing the rules more orthogonally, but since that orthogonality allows a few additional meaningful overload sets, there hasn’t been any hurry to “fix” it. In particular, it might work well with the proposal for deducing this that’s currently under consideration.

Elainaelaine answered 13/5, 2021 at 14:57 Comment(5)
Does that mean the above example is well-formed in the current standard?Sihun
@xmh0511: Yes, it is (though I believe the ref-qualifier has no effect in this particular case).Elainaelaine
though I believe the ref-qualifier has no effect in this particular case Absolutely, according to your confirmation, in the current draft, whether one of the declarations in the example has a ref-qualifier or not, it does not affect the result that the two declarations do not correspond(since they do not have the same cv-qualifier). However, in the older standard(Specifically, [over.load#2.3]), adding the ref-qualifier to one of the declarations(but not both) will make the example be ill-formed. Hence, in order to emphasize the case, I adopted the above example comes here.Sihun
@xmh0511: The point of "no effect" is that this ref-qualifier doesn't affect overload resolution (or the validity of the function body).Elainaelaine
The re-qualifier affect the overload set in the past. For instance, struct A{ void show() &{} //#1 void show(){} //#2 }; In the current draft, the definition for A itself is well-formed and alvalue.show() should be ambiguous since the implicit parameters are all A&. However, in the c++20 standard, the definition of the class A is ill-formed itself. The latest compiler does not obey the current draft.Sihun

© 2022 - 2024 — McMap. All rights reserved.