public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51331] New: bad code generated when explicitly calling auto-generated constructor of virtual base
@ 2011-11-28 12:18 zhezherun at yandex dot ru
  2011-11-29  5:28 ` [Bug c++/51331] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: zhezherun at yandex dot ru @ 2011-11-28 12:18 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51331
           Summary: bad code generated when explicitly calling
                    auto-generated constructor of virtual base
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zhezherun@yandex.ru


If a virtual base class has an auto-generated default constructor, explicitly
calling it from the derived class' constructor can result in bad code. The
following stripped-down example reproduces the issue:


#include <iostream>

struct A {
    A(): x(10) {}
    virtual ~A() {}

    int x;
};

struct B: public virtual A {
};

struct C: public virtual A {
};

struct D: public B, virtual public C {
    D(): B(), C() {}  // note an explicit call to C() which is auto-generated
};

int main() {
    D* d = new D();
    std::cout << d->x << std::endl;

    // Crashes here with the following message:
    // *** glibc detected *** ./test: free(): invalid next size (fast)
    delete d;
}


This code used to work correctly in gcc 4.1.2 but crashes in gcc 4.6.2 on i386
(both -m32 and -m64).


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

end of thread, other threads:[~2011-12-16 23:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-28 12:18 [Bug c++/51331] New: bad code generated when explicitly calling auto-generated constructor of virtual base zhezherun at yandex dot ru
2011-11-29  5:28 ` [Bug c++/51331] " pinskia at gcc dot gnu.org
2011-11-29 10:09 ` zhezherun at yandex dot ru
2011-11-29 13:11 ` paolo.carlini at oracle dot com
2011-12-14 23:40 ` [Bug c++/51331] [4.6/4.7 Regression] " pinskia at gcc dot gnu.org
2011-12-16 18:59 ` jason at gcc dot gnu.org
2011-12-16 22:35 ` jason at gcc dot gnu.org
2011-12-16 23:01 ` jason at gcc dot gnu.org
2011-12-16 23:03 ` jason at gcc dot gnu.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).