This is the mail archive of the gcc-bugs@gcc.gnu.org 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]

egcs-1.1a regression?


Hi!

Below I've included a short program which gives wrong results when compiled
with optimization (-O). I reported this before, but got no response. Since the
problem is still present in the release, I try it again.

Some notes:
- The errors were produced with egcs-19980824 and egcs-1.1a on
   i686-pc-linux-gnulibc1 and powerpc-ibm-aix4.2.1.0.
- If the template operator below is commented out, the code works fine.
  This template appears in the STL header stl_relops.h, so whenever this header
  is included, the bug is triggered.
- The wrong behaviour goes away when 'inline' is removed from the template
  definition.
- The loop doesn't do anything, but is necessary to produce the bug.
- The problem was not present in egcs-1.0.3a and earlier releases.

------cut here-------

#include <iostream>
#include <cstdlib>

template <class T>
inline bool operator!=(const T& x, const T& y) {
  return !(x == y);
}

typedef enum {val1, val2} FOO;

int main()
  {
  FOO foo = val1;

  for (int m=0; m<2; ++m)
    {
    if (rand() < (-1)) // never happens
      {
      foo = val2;
      cout << "How do we get here?" << endl;
      }
    }

  if (foo != val2)  // should be always true!
    cout << "Everything OK." << endl;
  else
    cout << "There must be a problem." << endl;
  }

------cut here-------

The output is:
~/bug>eg++ bug.cc
~/bug>a.out
Everything OK.
~/bug>eg++ -O bug.cc
~/bug>a.out
There must be a problem.

Sorry for the silly program, but the code where I discovered the problem
is far too long.

If this is not valid C++ code or if I missed something, please tell me!
Please cc your replies to me, since I'm not on the list.

If you need further information, please ask!

Martin Reinecke (martin@mpa-garching.mpg.de)



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