From Bugzilla Helper: User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.2.22-6.2.3a i686) Description of problem: The C++ compiler from package gcc-c++-2.96-112.7.1 incorrectly assigns addresses for temporaries when compiling with -O and using inline functions. The attached program (a.cc) prints the address of each object as it is constructed and as it is destroyed. You can see that two of the temporaries are assigned to the same location in memory and both are simultaneously alive (that is, both are constructed, then both are destroyed). This bug does not occur if the program is compiled without -O or if the function "func" is not declared as inline. Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: 1. Compile the attached program: g++ -O a.cc 2. Run the executable: ./a.out 3. Check the output, and see that two constructors are called for the same address, then two destructors are called for that address. Actual Results: [stern@ida x]$ g++ -O a.cc [stern@ida x]$ ./a.out Cons-1 at 0xbffffaf0 Cons-1 at 0xbffffae0 Cons-2 at 0xbffffb00 Cons-1 at 0xbffffaf0 Cons-2 at 0xbffffb10 Dest at 0xbffffb00 Dest at 0xbffffaf0 Dest at 0xbffffaf0 Dest at 0xbffffae0 Dest at 0xbffffb10 Expected Results: The second line of output saying "Cons-1 at 0xbffffaf0" should refer to a different address, and similarly the second line saying "Dest at 0xbffffaf0" should refer to that different address. Alternatively, the address could be reused if the first destructor was called before the second constructor. Additional info:
Created attachment 88486 [details] C++ source file to demonstrate the compiler bug in action
g++ 3.2 in 8.0 gets this right