Enquiry
Jonathan Wakely
jwakely.gcc@gmail.com
Sun Jan 30 11:17:17 GMT 2022
Meta-comment: a subject line of "Enquiry" is very vague, and most commonly
used by spammers and phishers. Your enquiry is about undefined behaviour
due to a missing return, which would have been a much better subject.
On Sun, 30 Jan 2022, 09:48 Theodore Papadopoulo, <
Theodore.Papadopoulo@inria.fr> wrote:
> 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.
>
>
More information about the Gcc
mailing list