Opened 8 years ago

Last modified 8 years ago

#10310 new Bugs

serialization/smart_cast.hpp uses dynamic_cast and breaks non-RTTI builds

Reported by: Mika Fischer <mika.fischer@…> Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

When serializing through a pointer to a polymorphic base class, dynamic cast is invoked in line 204, thus making it impossible to serialize via base pointer without RTTI.

Change History (5)

comment:1 by Robert Ramey, 8 years ago

I am very interested in address this as well as you're related observation regarding collections helper. I think both of these are fixable - but not as easily as one might think.

I've always wanted the serialization library to be usable in a non-RTTI environment and included code to permit this. Unfortunately, I only included one test to verify this. This test actually verifies the ability of types using different systems to inter operate. Since you're actually using this, you might want to make a couple of tests to catch these kinds of errors. If you do this, please follow the schema for the current tests which can be applied to any archive type. This would make it much easier for me to incorporate such tests. I would hope that just a few such tests would give the the assurance that the serialization library would be useful in a non-RTTI environment.

It's also possible that creation of these tests would uncover a couple of "gotchas" which should be described in the documentation. We can incorporate that as well - if necessary a new section for this special case.

Robert Ramey

comment:2 by Mika Fischer <mika.fischer@…>, 8 years ago

Well, with 1.55.0, the existing test case (test_no_rtti.cpp) already triggers this bug (and #8400) if it is compiled without RTTI. So getting the existing test case to work when RTTI is disabled in the compiler would probably go a long way towards fixing the existing issues with RTTI.

I'm pretty sure #10280 is also triggered by the test case, but with 1.56.0, it does not compile for me

% g++ test_no_rtti.cpp polymorphic_{base.cpp,derived1.cpp,derived2.cpp} /shared/distlibs/dists/arch-glibc2.19-gcc4.9.1-x86_64/boost_1_56_0/lib/libboost_{serialization.a,system.a,filesystem.a}
/tmp/cc15E2ee.o: In function `boost::archive::text_iarchive::text_iarchive(std::istream&, unsigned int)':
test_no_rtti.cpp:(.text._ZN5boost7archive13text_iarchiveC2ERSij[_ZN5boost7archive13text_iarchiveC5ERSij]+0x36): undefined reference to `boost::archive::detail::shared_ptr_helper::shared_ptr_helper()'
/tmp/cc15E2ee.o: In function `boost::archive::text_iarchive::~text_iarchive()':
test_no_rtti.cpp:(.text._ZN5boost7archive13text_iarchiveD2Ev[_ZN5boost7archive13text_iarchiveD5Ev]+0x24): undefined reference to `boost::archive::detail::shared_ptr_helper::~shared_ptr_helper()'
collect2: error: ld returned 1 exit status

We have decided not to pursue boost serialization without RTTI any further at this time. Buf if you have specific questions or requests, I'll see what I can do to help.

comment:3 by Robert Ramey, 8 years ago

I'm totally convinced of this. test_no_rtti isn't really named correctly. I tests the inter operability of classes using differing type identification systems. In order to test this it chooses two systems to use in the test - and one of them is rtti.

"When serializing through a pointer to a polymorphic base class, dynamic cast is invoked in line 204, thus making it impossible to serialize via base pointer without RTTI."

line 204 - but which file?

Robert Ramey

comment:4 by Robert Ramey, 8 years ago

btw - I've fixed the helper collection issue on my local machine. Will check in after some more testing.

comment:5 by Mika Fischer <mika.fischer@…>, 8 years ago

Well, I guess my point is that no additional tests are necessary. The existing test just needs to be compiled without RTTI to catch all relevant bugs.

The dynamic_cast is invoked in serialization/smart_cast.hpp:204 in 1.55.0 and also in master on github.

Note: See TracTickets for help on using tickets.