public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23643] New: Incorrect conversion from derived to empty base class
@ 2005-08-30 20:16 bduong at progress dot com
  2005-08-30 20:28 ` [Bug c++/23643] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 4+ messages in thread
From: bduong at progress dot com @ 2005-08-30 20:16 UTC (permalink / raw)
  To: gcc-bugs

It appears that the implicit conversion from a derived to an empty base class
is incorrect.

Consider the following code:

empty.cc:

#include <stdio.h>

class simple_base {
public:
  int sb;
};

class empty_base {
public:
  void test_eb() {
    printf("empty_base this @ %p\n", this);
  }
};

class class1 : public simple_base, public empty_base {
public:
  int c1;

  void test(empty_base* p) {
    printf("empty_base @ %p\n", p);
  }
};

class class2 {
public:
  int c2;
  class1 c1;
  int i3;

  void test(class1* p) {
    printf("class1 @ %p, i3 @ %p\n", p, &i3);
    c1.test(p);

    printf("empty_base should be at %p\n", (char*)p +
sizeof(simple_base));
    c1.test_eb();
  }
};

int main (int argc, char * const argv[]) {
  class2 c2;
  printf("class2 @ %p\n", &c2);
  c2.test(&c2.c1);
  return 0;
}

compiling this using:

g++ empty.cc and executing results in:
class2 @ 0xbfffce50
class1 @ 0xbfffce54, i3 @ 0xbfffce5c
empty_base @ 0xbfffce54
empty_base should be at 0xbfffce58
empty_base this @ 0xbfffce54

I would have expected the output to be:

class2 @ 0xbfffce50
class1 @ 0xbfffce54, i3 @ 0xbfffce5c
empty_base @ 0xbfffce58
empty_base should be at 0xbfffce58
empty_base this @ 0xbfffce58

version of gcc:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-52)


Thanks,

Bao.

-- 
           Summary: Incorrect conversion from derived to empty base class
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bduong at progress dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/23643] Incorrect conversion from derived to empty base class
  2005-08-30 20:16 [Bug c++/23643] New: Incorrect conversion from derived to empty base class bduong at progress dot com
@ 2005-08-30 20:28 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-30 20:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-30 20:21 -------
Someone will have to look this up in the ABI since this is an ABI issue.
But I think is okay as the base class is empty and takes no space at all.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ABI


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


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

* [Bug c++/23643] Incorrect conversion from derived to empty base class
       [not found] <bug-23643-11269@http.gcc.gnu.org/bugzilla/>
  2006-10-12  0:56 ` bangerth at dealii dot org
@ 2007-01-12  8:18 ` jbuck at gcc dot gnu dot org
  1 sibling, 0 replies; 4+ messages in thread
From: jbuck at gcc dot gnu dot org @ 2007-01-12  8:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jbuck at gcc dot gnu dot org  2007-01-12 08:18 -------
Andrew is right, this isn't a bug, and is in fact required by the ABI.
See http://www.codesourcery.com/cxx-abi/abi.html#class-types, section II,
subsection 3.  "First, attempt to place D at offset 0."  No rule prevents doing
this, so that is where it lands.


-- 

jbuck at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/23643] Incorrect conversion from derived to empty base class
       [not found] <bug-23643-11269@http.gcc.gnu.org/bugzilla/>
@ 2006-10-12  0:56 ` bangerth at dealii dot org
  2007-01-12  8:18 ` jbuck at gcc dot gnu dot org
  1 sibling, 0 replies; 4+ messages in thread
From: bangerth at dealii dot org @ 2006-10-12  0:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at dealii dot org  2006-10-12 00:56 -------
Why exactly do you think that the empty base should not be located at
the same address as the simple_base base object?

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |WAITING


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


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

end of thread, other threads:[~2007-01-12  8:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-30 20:16 [Bug c++/23643] New: Incorrect conversion from derived to empty base class bduong at progress dot com
2005-08-30 20:28 ` [Bug c++/23643] " pinskia at gcc dot gnu dot org
     [not found] <bug-23643-11269@http.gcc.gnu.org/bugzilla/>
2006-10-12  0:56 ` bangerth at dealii dot org
2007-01-12  8:18 ` jbuck at gcc dot gnu 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).