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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If we add [[nodiscard]] to the constructors of the standard exception types
then we get a warning with no compiler changes needed:

struct Exception
{
    [[nodiscard]] Exception(const char*) { }
};

int divide(int num, int denom) {
    if (denom == 0)
    {
        Exception("division by zero");
    }
    return num / denom;
}

It should work to do `struct [[nodiscard]] Exception` instead of putting it on
each constructor, but that's PR 85973

Reply via email to