This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/66617] New: C++11 {brace} initialisation of virtually inherited derived class = failure to override base virtual function, unless all base ctors have same signature


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66617

            Bug ID: 66617
           Summary: C++11 {brace} initialisation of virtually inherited
                    derived class = failure to override base virtual
                    function, unless all base ctors have same signature
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: db0451 at gmail dot com
  Target Milestone: ---

Created attachment 35822
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35822&action=edit
Original problem pattern

Example steps:

Create the following struct hierarchy:

A > > C
v
v
B

With
=> struct A containing a pure virtual function
=> B and C taking public virtual inheritance from A.

Now create struct D inheriting from B and C and implementing the pure virtual
function.


This will not work when D initialises its base classes using the new {brace}
initialisation UNLESS, and only if, all base constructors have the same
function signature/number of arguments.

=> Pure virtual function in base generates errors about being unable to
allocate abstract classes B and C
=> Non-pure vfunc generates undefined references to the pure vfunc in B and C.


Contructing D using (parentheses) initialisation works fine and leads to the
expected result. This is as simple as replacing the brackets in the
instantiation, nothing more.


Supporting evidence are:

=> original thread on StackOverflow, by my handle @underscore_d - containing
original problem code using {brace} initialisation as attached in
"virtual2.cpp" - with working example (same ctor signatures) "virtual3.cpp"
====>
http://stackoverflow.com/questions/30967490/virtual-inheritance-pure-v-function-in-base-fails-with-abstract-pure-error?noredirect=1#comment49967008_30967490
=> minimal replication steps outlined by fellow SO user @0x499602D2

Attached also is "virtual4.cpp", which as mentioned, is merely "virtual2.cpp"
with the instantiation of the final derived class changed to use (parenthesis)
initialisation instead of {braces}


Using G++ 4.9.2 from MSYS2 64-bit, latest version I was able to find.

Many thanks

Daniel B.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]