Before creating a bug report, I want to check with the GCC community (all the more that checking that the problem has not yet been reported is complicated at leat for me).

The following (admitedly buggy) program generates a segmentation violation on fedora 35 (this is with g++ 11.2.1 20211203 (Red Hat 11.2.1-7) (GCC)) when compiled with -O3 (other versions replacing unisgned by std::string may trigger the exception instead of the segv)

bool assert_sthg(const unsigned s) {
    if (s==123)
        throw 1;
}

int main() {
    assert_sthg(0);
    return 0;
}

When compiling, we indeed get a warning:

test.C:4:1: warning: control reaches end of non-void function [-Wreturn-type]

I can well understand that the program being buggy that the optimizer is allowed to do anything including the observed segmentation violation.
Yet the result is quite surprising....
The question is, in that case, wouldn't it be better to turn the warning into an error at -O3 ?

    Thank's for any input.

        Theo.

Reply via email to