From Jordi Torres, "We have a code using gcc with -Wextra flag and using OSG as a third party library. It does not compile when importing <osgViewer/Viewer> failing in EventHandler and GUIEventHandler:

....

GUIEventHandler: In copy constructor 'osgGA::GUIEventHandler::GUIEventHandler(const osgGA::GUIEventHandler&, const osg::CopyOp&)':

/include/osgGA/GUIEventHandler:56:9: error: base class 'class osg::Object' should be explicitly initialized in the copy constructor [-Werror=extra]

It seems the diamond problem:

   A = osg::Object
  / \
 /   \--> Virtual inheritance
B     C
 \   /
  \ /
   D = EventHandler
   |
   |
   E = GUIEventHandler

The most derived class(E)  handles the instantiation of A (osg::Object), but all have to be responsible in case they are the ones instantiated.


In case A is not initialized in the copy constructor of derived classes the default constructor will be called, which seems a bug.

I've added osg::Object to the initalization list of EventHandler and GUIEventHandler copy constructors, because both classes are instantiables.
 "
This commit is contained in:
Robert Osfield 2014-01-17 13:59:29 +00:00
parent 354d79acd1
commit e04e03d695
2 changed files with 2 additions and 1 deletions

View File

@ -37,6 +37,7 @@ public:
EventHandler() {}
EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(eh,copyop),
osg::NodeCallback(eh, copyop),
osg::Drawable::EventCallback(eh, copyop) {}

View File

@ -54,7 +54,7 @@ public:
#if 1
GUIEventHandler() {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
EventHandler(eh, copyop) {}
osg::Object(eh, copyop), EventHandler(eh, copyop) {}
#else
GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):