https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84476

Albi <albrecht.guendel at web dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |albrecht.guendel at web dot de

--- Comment #7 from Albi <albrecht.guendel at web dot de> ---
Its 2025 now. GCC15.1.
This is not good, and there is no reason for it. 
This is broken.
This is dangerous. 
This is INCONSISTENT.
This has serious consequences for Werror=unused-result

Regarding the inconsistency: why does (&d)->func() generate a warning here?


https://godbolt.org/z/zcTEfEEeY

struct Base
{
    [[nodiscard]] virtual int func() { return 0;}
};

struct Derived: Base
{
    [[nodiscard]] int func() override { return 1; }
};


int main()
{
    Derived d;

    // WARNING HERE OK
    d.func();           

    // NO WARNING HERE - BROKEN SINCE 2018
    Base* b = &d;
    b->func();          

    // NO WARNING HERE - BROKEN SINCE 2018
    dynamic_cast<Derived*>(b)->func();

    // WARNING HERE  BUT WHY??? I invoke on a Derived*, same as next test case.
    (&d)->func();         

    // NO WARNING HERE - BROKEN SINCE 2018
    Derived* pd = &d;
    pd->func();
    return 0;
}

Reply via email to