On Sunday, 2 February 2014 at 09:56:06 UTC, Marc Schütz wrote:

auto x = *p;
if(!p) {
    do_something(x);
}

In the first step, the if-block will be removed, because its condition is "known" to be false. After that, the value stored into x is unused, and the dereference can get removed too.

With a good static analyzer, such as coverity, this program would be rejected anyway with "check_after_deref", if the compiler is smart enough to do the optimization, it could be smart enough to issue a warning as well!

Reply via email to