It's not about unit test, it's about communicating behavior.

I can see it being a thing, but I'm not sure that really requiring it in all circumstances is a symptom of a design problem.
Even the most pedantic of libraries I've worked with allows skipping the call to parent in some circumstances.

I agree that it requires some user experience to get a better understanding of this.



From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> on behalf of Bo Persson via Std-Proposals <std-proposals@lists.isocpp.org>
Sent: Sunday, August 18, 2024 9:30:18 AM
To: std-proposals@lists.isocpp.org <std-proposals@lists.isocpp.org>
Cc: Bo Persson <bo@bo-persson.se>
Subject: Re: [std-proposals] Attribute to require call to overridden base class function
 
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.


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