C++ Logo

std-proposals

Advanced search

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

From: Bo Persson <bo_at_[hidden]>
Date: Sun, 18 Aug 2024 09:30:18 +0200
On 2024-08-17 at 23:18, Billy via Std-Proposals 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 this have to be a compile time errror?

In my experience, missing the call happens very rarely, and will be
caught early in the unit tests.

Received on 2024-08-18 07:30:27