This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/24737] New: const bool& optimization error

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!
                        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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]