[PATCH][RFC] middle-end/46476 - resurrect -Wunreachable-code
Michael Matz
matz@suse.de
Wed Nov 24 17:51:56 GMT 2021
Hello,
On Wed, 24 Nov 2021, Richard Biener wrote:
> >> +/* Unreachable code in if (0) block. */
> >> +void baz(int *p)
> >> +{
> >> + if (0)
> >> + {
> >> + return; /* { dg-bogus "not reachable" } */
> >
> >Hmm? Why are you explicitely saying that warning here would be bogus?
>
> Because I don't think we want to warn here. Such code is common from
> template instantiation or macro expansion.
Like all code with an (const-propagated) explicit 'if (0)', which is of
course the reason why -Wunreachable-code is a challenge. IOW: I could
accept your argument but then wonder why you want to warn about the second
statement of the guarded block. The situation was:
if (0) {
return; // (1) don't warn here?
whatever++; // (2) but warn here?
}
That seems even more confusing. So you don't want to warn about
unreachable code (the 'return') but you do want to warn about unreachable
code within unreachable code (point (2) is unreachable because of the
if(0) and because of the return). If your worry is macro/template
expansion resulting if(0)'s then I don't see why you would only disable
warnings for some of the statements therein.
It seems we are actually interested in code unreachable via fallthrough or
labels, not in all unreachable code, so maybe the warning is mis-named.
Btw. what does the code now do about this situation:
if (0) {
something++; // 1
return; // 2
somethingelse++; // 3
}
does it warn at (1) or not? (I assume it unconditionally warns at (3))
Ciao,
Michael.
More information about the Gcc-patches
mailing list