Bug#446067: g++-4.1 in etch has incorrect output
Package: g++-4.1
Version: 4.1.1-21
The g++ shipped with debian is incorrect. g++ seems to be able to use
non-constant initializer for global variables (I don't known if this is
standard C++ behaviour) , but this doesn't work
when optimizations are on with the version of gcc shipped with debian.
I checked with other versions of gcc (4.2, 3.3) and it works perfectly.
I attach a sample test file and sample session.
Best Regards
Matthieu Lemerre
PS: I encountered the bug in fpu/fpu_const.cc in Bochs, so maybe the
debian package for bochs is affected by this bug too.
#if 0
~$ gcc test2.c
test2.c:29: error: initializer element is not constant
~$ g++ test2.c -Wall
test2.c: In function 'int main()':
test2.c:35: warning: format '%x' expects type 'unsigned int', but
argument 3 has type 'Bit64u'
~$ ./a.out
Reg: 3fff 0
~$ g++ test2.c -O2 -Wall
test2.c: In function 'int main()':
test2.c:35: warning: format '%x' expects type 'unsigned int', but
argument 3 has type 'Bit64u'
~$ ./a.out
Reg: 0 0
~$
~$ gcc -v
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
#endif
test2.c:
typedef unsigned long long Bit64u;
typedef signed int Bit32s;
typedef unsigned short Bit16u;
struct floatx80 {
Bit64u fraction;
Bit16u exp;
};
#define BX_CONST64(x) (x##LL)
#include <stdio.h>
inline struct floatx80 packFloatx80(int zSign, Bit32s zExp, Bit64u zSig)
{
struct floatx80 z;
z.fraction = zSig;
z.exp = (zSign << 15) + zExp;
return z;
}
extern const struct floatx80 Const_1;
const struct floatx80 Const_1 = packFloatx80(0, 0x3fff,
BX_CONST64(0x8000000000000000));
int
main()
{
struct floatx80 reg = Const_1;
printf("Reg: %x %x\n", reg.exp, reg.fraction);
}
Reply to: