C++ Logo

std-discussion

Advanced search

Re: trailing requires-clause for virtual function

From: mauro russo <ing.russomauro_at_[hidden]>
Date: Mon, 13 Jan 2025 23:33:46 +0100
ok,

it makes sense, as the referred §13.7.3-p4 allows, instead, a template
member function to be defined as non-overriding the virtual non-template
one.

Anyway, do you believe that specifying "for G" in §11.7.3 -p2 is just more
tedious ?



Il giorno lun 13 gen 2025 alle ore 23:08 Brian Bi <bbi5291_at_[hidden]> ha
scritto:

>
>
> On Mon, Jan 13, 2025 at 5:05 PM mauro russo via Std-Discussion <
> std-discussion_at_[hidden]> 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_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>>
>
>
> --
> *Brian Bi*
>

Received on 2025-01-13 22:33:58