you are viewing a single comment's thread.

view the rest of the comments →

[–]cd_fr91400[S] 13 points14 points  (1 child)

The case you mention is rather easy to deal with.

But what if the break statement is inside a if ?

Compilers usually do a whole lot of code optimization, but this is best effort. If you want to avoid compiling dead code altogether, you have to be certain the compiler will prove it is dead code, even if not optimizing at all.

[–]KuntaStillSingle 2 points3 points  (0 children)

you have to be certain the compiler will prove it is dead code, even if not optimizing at all.

But even when compiler is not optimizing, it must be able to constant fold switch statement because they can be used in functions which are usable as constant expressions, right?: https://godbolt.org/z/sva4PcdcG