egcs 19980824 bug report
Martin Reinecke
martin@mpa-garching.mpg.de
Wed Aug 26 02:31:00 GMT 1998
Hi!
Below I've included a short program which gives wrong results when compiled
with optimization (-O).
Some notes:
- The errors were produced with egcs-19980824 on i686-pc-linux-gnulibc1.
- If the template operator below is commented out, the code works fine.
This template appears in <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 versions.
------cut here-------
#include <cstdlib>
#include <iostream>
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>beg++ bug.cc
~/bug>a.out
Everything OK.
~/bug>beg++ -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)
More information about the Gcc-bugs
mailing list