[Bug c++/24737] New: const bool& optimization error
fredrik dot littmarck at propellerheads dot se
gcc-bugzilla@gcc.gnu.org
Tue Nov 8 16:39:00 GMT 2005
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.)
--
Summary: const bool& optimization error
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fredrik dot littmarck at propellerheads dot se
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24737
More information about the Gcc-bugs
mailing list