// Postet by [EMAIL PROTECTED]
// Compiler Error found:
//      gcc (GCC) 3.3.4 (pre 3.3.5 20040809)
//      under SuSE Linux kernel 2.6.8-24.10-default (i386)
//
// If this littel programm is compiled with the option -O2
// the assignment in the inline function data::data() is wrong.
// If I remove the 'inline' the result is correct.
//
// Compiled with: g++ -Wall error.cpp
//              -> OK, printout = 00000000:00000000
//
// Compiled with: g++ -Wall -O2 error.cpp
//              -> ERROR, printout = 00000000:bffff408
//
// Compiled with: g++ -Wall -O2 error.cpp,, but without 'inline'
//              -> OK, printout = 00000000:00000000
//

#include <stdlib.h>
#include <stdio.h>

typedef unsigned int uint32;
typedef unsigned long long uint64;

class data
{
 public:
    uint32 lo;
    uint32 hi;

    data ( uint32 num );
};

inline data::data ( uint32 num ) { *(uint64*)this = num; }


int main()
{
    printf("sizeof(uint32)=%d\n",sizeof(uint32));
    printf("sizeof(uint64)=%d\n",sizeof(uint64));
    printf("sizeof(data)  =%d\n",  sizeof(data));

    uint32 tab[] = { 0,0,0,0,0 };
    uint32 *p = tab;

    data D = data(*p++);
    printf("%08x:%08x\n",D.hi,D.lo);
}

-- 
           Summary: assignment error in inline function
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dirk at cle-mens dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20184

Reply via email to