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

            Bug ID: 97712
           Summary: Attribute nodiscard in virtual methods is ignored
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pacoarjonilla at yahoo dot es
  Target Milestone: ---

The standard attribute [[nodiscard]] is ignored if the function is virtual.
Versions GNU C++ trunk and GNU C++ 10.2 fails to issue a warning on the
following snippet:

>>>>>>>>>>>

struct B {
    [[nodiscard]] virtual int f() = 0;
};

struct D : public B {
    [[nodiscard]] int f() override {return 1;}
};

int main() {
    B * b = new D;
    b->f();         // GNU C++ does not warn about discarded value
}

<<<<<<<<<<<<<

Clang does issue a warning appropriately.

Reply via email to