On Mon, Jan 13, 2025 at 5:05 PM mauro russo via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
In the actual standard draft,

§11.7.3 [class.virtual] - p2, p6

read something that seems to be contradiction:

p2 text:
If a virtual member function F is declared in a class B, and, in a class D derived (directly or indirectly) from B, a declaration of a member function G corresponds (6.4.1) to a declaration of F , ignoring trailing requires-clauses, then G overrides F. ...

p6 text:
A virtual function shall not have a trailing requires-clause.

It seems the text of p2 allows the presence of trailing requires-clauses in virtual functions, both in the original and the overriding declarations (note the plural in p2 text), whereas p6 text states the opposite.

You don't know whether the derived class function is virtual until you check whether it overrides a virtual function from the base class. So you have to ignore the trailing requires-clause on the derived class function in order to check whether it overrides, and if it does, then the trailing requires-clause is ill-formed.
 

However, it's clear that constraints would not be manageable for virtual functions. Indeed, the comment during the example in p6 also reads more specifically that "virtual function cannot be constrained ".

Now, one might think that the part of p2 "ignoring trailing requires-clauses" does not necessarily mean that they can be present, and it might be read, instead, as a kind of confirmation that they cannot.
However, why specifying such a detail only for trailing requires-clauses, not even for type-constraints, and requires-clauses ? I mean, even these other forms of constraints cannot be present, from
§13.7.3 [temp.mem] - p3 and p4,
p3: "A member function template shall not be declared virtual."
p4: "A specialization of a member function template does not override a virtual function from a base class."


I guess that, for consistency, the part "ignoring trailing requires-clauses" should be removed.

--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion


--
Brian Bi