C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Attribute to require call to overridden base class function

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sat, 17 Aug 2024 22:41:31 +0100
On Sat, 17 Aug 2024, 22:20 Billy via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> Could C++ use an attribute to require derived classes to call the base
> class version of a function?
>
> struct A {
> virtual void f() [[required]] { }
> };
>
> struct B : A {
> void f() override {
> A::f(); // compiler warning if omitted
> }
> };
> Much like Objective-C's __attribute__((objc_requires_super))
>



Does it need to be in the standard?

Could it just be done as a compiler extension, at least as a first pass to
gather feedback and usage experience?

One of the nice things about attributes is the fact that implementations
can add their own.




>

Received on 2024-08-17 21:42:49