Yes, I've removed everything unnecessary to make the error show up, to not confound the problem.

a) yes, but it doesn't declare a member function and then implement it in the middle of the diamond
b) In my actual code, I'm using diamond inheritance of course, but it's not needed to make the code fail to compile.
c) It fails to compile on both apple LLVM 8.0.0 on osx, and on gcc 4.9 on ubuntu 12.04
d) not in the example, but in my project I need it to actually export. Removing the export makes the code compile, but that doesn't help me, since I want to do serialization

Note that I don't actually need to instantiate anything. I can remove `int main` entirely, and only compile an object file and it generates the same error.

To make the code compile, I can do multiple things: remove the text_oarchive include, remove the export directive, remove the virtual inheritance for `struct B`, remove the implementation of `void foo`, remove the serialization of base_object<B> from struct C...

 That makes the example compile, but doesn't tell me how to serialize an object with diamond inheritance, where a pure virtual method from the virtual base class is implemented by one of the classes in the middle.




On Thu, Oct 27, 2016 at 3:22 AM Robert Ramey <ramey@rrsd.com> wrote:
On 10/26/16 8:45 AM, Douwe Gelling wrote:
> Hi all,
>
> When trying to serialize a class with a virtual base class, I'm getting
> compilation errors. It seems to be part of a bug in type_traits, but I'm
> wondering if anyone knows a workaround for making it work anyhow.
>
> ultimately, the error boils down to "error: virtual function 'A::foo'
> has more than one final overrider in
> 'boost_type_traits_internal_struct_X'", using the code listing below..
> It's simplified as much as possible, but obviously I need virtual
> inheritance due to using diamond inheritance.
>
>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/serialization/base_object.hpp>
> #include <boost/serialization/export.hpp>
> #include <boost/serialization/serialization.hpp>
>
> struct A
> {
>   virtual ~A(){};
>   virtual void foo() = 0;
>   template <class Archive>
>   void serialize(Archive& ar, const unsigned int version)
>   {
>   }
> };
>
> struct B : public virtual A
> {
>   virtual void foo()
>   {
>   }
>   template <class Archive>
>   void serialize(Archive& ar, const unsigned int version)
>   {
>     ar& boost::serialization::base_object<A>(*this);
>   }
> };
>
> struct C : public B
> {
>   template <class Archive>
>   void serialize(Archive& ar, const unsigned int version)
>   {
>     ar& boost::serialization::base_object<B>(*this);
>   }
> };
>
> BOOST_CLASS_EXPORT(C);
>
> int main()
> {
>   C c;
>   return 0;
> }
>

Just some quick observations:

a) there is a example/test for diamond inheritance in the test suite
b) I don't see diamond inhertance in your example.
c) I might be helpful to indicate the compiler
d) Your not actually doing an serialization so I doubt you need "export"

I would keep cutting down the example until it starts to compile.  I'm
very doubtful that this has anything to do with serialization or diamond
inheritance

Robert Ramey


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users