public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14808] New: Undefined results with virtual base classes
@ 2004-04-01  9:05 dannysmith at users dot sourceforge dot net
  2004-04-01 12:09 ` [Bug c++/14808] [3.4/3.5 Regression] [win32] " pinskia at gcc dot gnu dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2004-04-01  9:05 UTC (permalink / raw)
  To: gcc-bugs

With both 3.4.0 (20040327) and trunk (20040331), I am getting segfaults
or unexpected results with virtual base classes on i386-pc-mingw32


Here is an illustration:

// vbase.cc
#include <stdio.h>

class Base
{
public:
 // int base_var;
  virtual char* vf() const = 0;
  virtual ~Base() {}
};

class D1 :  public Base
{
public:
  char* vf() const { return "D1"; }
};


class D2 :  virtual public Base
{
public:
  char* vf() const { return "D2"; }
};


void test1()
{
  Base* b1 = new D1;
  printf("%s\n", b1->vf());
}

void test2()
{
  Base* b2 = new D2;
  printf("%s\n", b2->vf());
}

int main()
{
 test1();
 test2();
 return 0;
}

//end vbase.cc

With trunk:

When compiled without optimisation
g++ -ovbase0 -Wall -O0 vbase.cc

I get successful build, with no warnings. But executing vbase0 causes
segfault.

Ditto with -O1

When compiled with -O2 optimisation
g++ -ovbase2 -Wall -O2 vbase.cc

executing vbase2 outputs:

D1
2D2


When I add -g:
g++ -ovbase0g -g -Wall -O0 vbase.cc
Executing vbase0g doesn't segfault. But it doesn't produce _any_ 
output either.  Ditto with -O1 -g.


This is regression from 3.3.3 which output 

D1
D2

at all levels of optimisation

2.95.3 also produced the correct output.


If I add a variable (the commented out int base_var) to the
base class, the executable built with 3.4.0 and trunk executes
without problem and produces the correct output.

If I comment out the "virtual" keyword in D2's definition, I 
also get correct output with 3.4.0 and trunk.


Danny

-- 
           Summary: Undefined results with virtual base classes
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dannysmith at users dot sourceforge dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-mingw32
  GCC host triplet: i686-pc-mingw32
GCC target triplet: i686-pc-mingw32


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


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

end of thread, other threads:[~2004-06-16 22:59 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-01  9:05 [Bug c++/14808] New: Undefined results with virtual base classes dannysmith at users dot sourceforge dot net
2004-04-01 12:09 ` [Bug c++/14808] [3.4/3.5 Regression] [win32] " pinskia at gcc dot gnu dot org
2004-04-05 21:59 ` dannysmith at users dot sourceforge dot net
2004-04-07 21:02 ` dannysmith at users dot sourceforge dot net
2004-04-07 21:34 ` pinskia at gcc dot gnu dot org
2004-04-07 22:11 ` mmitchel at gcc dot gnu dot org
2004-04-08 21:23 ` mmitchel at gcc dot gnu dot org
2004-04-08 22:16 ` cvs-commit at gcc dot gnu dot org
2004-04-08 22:31 ` cvs-commit at gcc dot gnu dot org
2004-04-08 22:35 ` dannysmith at users dot sourceforge dot net
2004-06-07 12:16 ` dank at kegel dot com
2004-06-07 14:29 ` mark at codesourcery dot com
2004-06-08  6:31 ` cvs-commit at gcc dot gnu dot org
2004-06-08  6:33 ` wilson at specifixinc dot com
2004-06-16 22:59 ` cvs-commit 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).