Index: boost/serialization/export.hpp =================================================================== --- boost/serialization/export.hpp (revision 43875) +++ boost/serialization/export.hpp (working copy) @@ -112,6 +112,15 @@ ); } +// This trait is used to force the compiler to do a dependent name +// lookup on instantiate_ptr_serialization. When classes are exported, +// they specialize this trait to inherit from mpl::true_. This in +// turn causes a different set of overloads to be selected. The key +// thing is that the name lookup is delayed to instantiation time. +template +struct force_dependent_name_lookup + : boost::mpl::false_ {}; + template struct guid_initializer { @@ -119,7 +128,8 @@ // generates the statically-initialized objects whose constructors // register the information allowing serialization of T objects // through pointers to their base classes. - instantiate_ptr_serialization((T*)0, 0); + instantiate_ptr_serialization((T*)0,0, + typename force_dependent_name_lookup::type()); return *this; } const guid_initializer & export_guid(char const* key, mpl::true_){ @@ -144,7 +154,14 @@ } // namespace archive } // namespace boost +// Internal macro: This macro +#define BOOST_SERIALIZATION_FORCE_DEP_NAME_LOOKUP(T) \ +namespace boost { namespace archive { namespace detail { \ +template<> struct force_dependent_name_lookup : public mpl::true_{}; \ +}}} + #define BOOST_CLASS_EXPORT_GUID(T, K) \ +BOOST_SERIALIZATION_FORCE_DEP_NAME_LOOKUP(T) \ namespace \ { \ ::boost::archive::detail::guid_initializer< T > const & \ Index: boost/archive/detail/register_archive.hpp =================================================================== --- boost/archive/detail/register_archive.hpp (revision 43875) +++ boost/archive/detail/register_archive.hpp (working copy) @@ -4,6 +4,8 @@ #ifndef BOOST_ARCHIVE_DETAIL_REGISTER_ARCHIVE_DWA2006521_HPP # define BOOST_ARCHIVE_DETAIL_REGISTER_ARCHIVE_DWA2006521_HPP +#include + namespace boost { namespace archive { namespace detail { template @@ -17,26 +19,26 @@ struct _ptr_serialization_support : ptr_serialization_support { - typedef int type; + typedef void type; }; -// This function gets called, but its only purpose is to participate -// in overload resolution with the functions declared by -// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below. -template -void instantiate_ptr_serialization(Serializable*, int) {} +template +struct is_oarchive : public Archive::is_loading {}; -// The function declaration generated by this macro never actually -// gets called, but its return type gets instantiated, and that's -// enough to cause registration of serialization functions between -// Archive and any exported Serializable type. See also: -// boost/serialization/export.hpp +// ADL causes _ptr_serialization_support to be instantiated for all +// archives that get registered. This function is actually called. +// See also: boost/serialization/export.hpp # define BOOST_SERIALIZATION_REGISTER_ARCHIVE(Archive) \ namespace boost { namespace archive { namespace detail { \ \ template \ -typename _ptr_serialization_support::type \ -instantiate_ptr_serialization( Serializable*, Archive* ); \ +typename boost::enable_if, \ + typename \ + _ptr_serialization_support::type >::type \ +instantiate_ptr_serialization( Serializable*, \ + Archive*, \ + boost::mpl::true_){} \ \ }}} Index: libs/serialization/test/test_exported.cpp =================================================================== --- libs/serialization/test/test_exported.cpp (revision 43875) +++ libs/serialization/test/test_exported.cpp (working copy) @@ -18,11 +18,11 @@ } #endif +#include #include #include #include #include "test_tools.hpp" -#include #include "base.hpp"