public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20184] assignment error in inline function
  2005-02-24 14:34 [Bug c++/20184] New: assignment error in inline function dirk at cle-mens dot de
@ 2005-02-24 14:34 ` falk at debian dot org
  2005-02-24 15:01 ` dirk at cle-mens dot de
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: falk at debian dot org @ 2005-02-24 14:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From falk at debian dot org  2005-02-24 10:21 -------
You are accessing an object of type "class data" via a pointer to uint64, which
is not allowed in C++. So this is invalid.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/20184] New: assignment error in inline function
@ 2005-02-24 14:34 dirk at cle-mens dot de
  2005-02-24 14:34 ` [Bug c++/20184] " falk at debian dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: dirk at cle-mens dot de @ 2005-02-24 14:34 UTC (permalink / raw)
  To: gcc-bugs

// Postet by dirk@cle-mens.de
// 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/20184] assignment error in inline function
  2005-02-24 14:34 [Bug c++/20184] New: assignment error in inline function dirk at cle-mens dot de
  2005-02-24 14:34 ` [Bug c++/20184] " falk at debian dot org
@ 2005-02-24 15:01 ` dirk at cle-mens dot de
  2005-02-24 15:04 ` dirk at cle-mens dot de
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: dirk at cle-mens dot de @ 2005-02-24 15:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dirk at cle-mens dot de  2005-02-24 10:35 -------
The cast is, perhaps, illegal. But after the cast there is an assignment from
uint32 to uin64. And that assignment does not work.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/20184] assignment error in inline function
  2005-02-24 14:34 [Bug c++/20184] New: assignment error in inline function dirk at cle-mens dot de
  2005-02-24 14:34 ` [Bug c++/20184] " falk at debian dot org
  2005-02-24 15:01 ` dirk at cle-mens dot de
@ 2005-02-24 15:04 ` dirk at cle-mens dot de
  2005-02-24 15:14 ` falk at debian dot org
  2005-02-24 15:16 ` falk at debian dot org
  4 siblings, 0 replies; 6+ messages in thread
From: dirk at cle-mens dot de @ 2005-02-24 15:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dirk at cle-mens dot de  2005-02-24 10:38 -------
The reinterpret_cast solves the problem with this old code.

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


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/20184] assignment error in inline function
  2005-02-24 14:34 [Bug c++/20184] New: assignment error in inline function dirk at cle-mens dot de
                   ` (2 preceding siblings ...)
  2005-02-24 15:04 ` dirk at cle-mens dot de
@ 2005-02-24 15:14 ` falk at debian dot org
  2005-02-24 15:16 ` falk at debian dot org
  4 siblings, 0 replies; 6+ messages in thread
From: falk at debian dot org @ 2005-02-24 15:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From falk at debian dot org  2005-02-24 10:57 -------
(In reply to comment #2)
> The cast is, perhaps, illegal.

No, the cast is fine. The access is bad.

> But after the cast there is an assignment from
> uint32 to uin64. And that assignment does not work.

Since this has undefined behaviour, it cannot possibly "not work".


-- 


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/20184] assignment error in inline function
  2005-02-24 14:34 [Bug c++/20184] New: assignment error in inline function dirk at cle-mens dot de
                   ` (3 preceding siblings ...)
  2005-02-24 15:14 ` falk at debian dot org
@ 2005-02-24 15:16 ` falk at debian dot org
  4 siblings, 0 replies; 6+ messages in thread
From: falk at debian dot org @ 2005-02-24 15:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From falk at debian dot org  2005-02-24 10:58 -------
(In reply to comment #3)
> The reinterpret_cast solves the problem with this old code.
> 
> inline data::data ( uint32 num ) { *reinterpret_cast<uint64*>(this) = num; }

That is pure luck; the code is still invalid.


-- 


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-02-24 10:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-24 14:34 [Bug c++/20184] New: assignment error in inline function dirk at cle-mens dot de
2005-02-24 14:34 ` [Bug c++/20184] " falk at debian dot org
2005-02-24 15:01 ` dirk at cle-mens dot de
2005-02-24 15:04 ` dirk at cle-mens dot de
2005-02-24 15:14 ` falk at debian dot org
2005-02-24 15:16 ` falk at debian dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).