Re: unreachable code in 'vector'

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



In article <ekoP1pTYFHA.228@xxxxxxxxxxxxxxxxxxxx>, spoo@xxxxxxxxx
says...

[ ... ]

> Well thanks for the information. This is not what I would have
> expected. I would have thought that this warning would have
> been emitted without optimization. I assumed (probably
> incorrectly given your explanation) that the code was being
> optimized out, sort of like saying if(false) { ...}
>
> It certainly seems this way in other places.
> It's only the one in vector that the OP posted
> that I've seen that has different behavior based
> on the build settings.

The warning _can_ be emitted in a debug build if the unreachability
of the code is sufficiently "obvious" -- something like 'if (false)'
will show up essentially every time. OTOH, consider something like
this:

bool x = false;

if (x) {
whatever();
}

Now, it's pretty obvious to you or me that x will be false when the
if statement is executed, so the call to whatever() is unreachable --
but I doubt there's a compiler around that will detect that with
optimization turned off.

In all honesty, I'm not sure there's one that will detect it with
optimization turned ON either, but that's more or less irrelevant --
the point is that it _could_ be detected, but almost certainly
wouldn't be without optimization. Past that, it's mostly a matter of
what kinds of things a particular optimizer looks at, which can be
somewhat difficult to predict (to put it mildly).

Doing a quick test with the current MS compiler on this code, a
glance at the object code shows that it DOES detect that the call is
unreachable, but doesn't issue a warning to say so...

--
Later,
Jerry.

The universe is a figment of its own imagination.
.



Relevant Pages

  • Re: dereferencing type-punned pointer will break strict-aliasing rules
    ... I don't see any reason why optimization should change things much ... Anyway, this is the warning: ... and the pad field in lclparams in an int. ... What doesn't the compiler like? ...
    (comp.lang.c)
  • Bogus longjmp clobber warning?
    ... hair out over error logging. ... extern int pthread_rwlock_rdlock; ... If this is compiled without optimization, ... I get a warning that pt_errno might be ...
    (comp.os.linux.development.apps)
  • dereferencing type-punned pointer will break strict-aliasing rules
    ... generates the warning below, but ONLY if the gcc compiler is at -O2 or -O3. ... I don't see any reason why optimization should change things much in this piece of code - there's no way to optimize it out and I have verified that this particular line does what it should no matter how the program is compiled. ... and the pad field in lclparams in an int. ...
    (comp.lang.c)
  • Re: [OT] Re: Questions about pointers to objects and pointers to functions
    ... >>> effective type of the object, and I believe that this optimization ... >> What I think you're saying is that, even though the compiler ... >> because that information might enable further optimization. ... warning check than to reflect whether the compiler considers the ...
    (comp.lang.c)
  • Re: event id: 1025
    ... functionality of the system, and is not a cause for concern. ... Event Type: Warning ... Event Source: MSExchangeIS Mailbox Store ... Error: -1102 Warning: fail to apply search optimization to folder (FID ...
    (microsoft.public.exchange.admin)