When using gcc 4.0.0 or 4.0.1 on MacOS, the following code fails when optimizations (-O1 - -O3) is turned on: --- snip --- bool TestFoo(const bool& trueBool) { CFoo foo; // bool falseBool = trueBool ? false: true; // This works! bool falseBool = !trueBool; // This does not work! if (falseBool != foo.GetFalse()) { if (!falseBool) { // Should never be executed! foo.DoSomething(1); return true; } } return false; } int main (int /*argc*/, char * const /*argv[]*/) { bool trueBool = true; if (TestFoo(trueBool)) { return -1; // Error! } return 0; } --- snip --- The code works as intended when optimizations are turned off. It seems to be the ! operator not working with const bool&, but modifying the code in other ways may also solve the problem. (Try putting the CFoo class in the same module, or remove the inner if statement in TestFoo.)
I Think this has already been fixed in 4.0.2 by the patch for PR 23326.
Actually on second thought, this is a dup of bug 23326. *** This bug has been marked as a duplicate of 23326 ***
Created attachment 10175 [details] Test Case
Note also you are using Apple's compiler and should report this to them.