C++ Logo

std-discussion

Advanced search

trailing requires-clause for virtual function

From: mauro russo <ing.russomauro_at_[hidden]>
Date: Mon, 13 Jan 2025 23:05:44 +0100
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.

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.

Received on 2025-01-13 22:05:56