This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/24737] New: const bool& optimization error
- From: "fredrik dot littmarck at propellerheads dot se" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Nov 2005 16:39:45 -0000
- Subject: [Bug c++/24737] New: const bool& optimization error
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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