Ticket #1711: header_ordering_fix.patch

File header_ordering_fix.patch, 5.0 KB (added by Sohail Somani <boost-trac@…>, 15 years ago)

Here is a fix which forces dependent name lookup and uses ADL to instantiate the appropriate classes. I am very doubtful that this will work on any other compiler since I haven't tried!

  • boost/serialization/export.hpp

     
    112112    );
    113113}
    114114
     115// This trait is used to force the compiler to do a dependent name
     116// lookup on instantiate_ptr_serialization. When classes are exported,
     117// they specialize this trait to inherit from mpl::true_. This in
     118// turn causes a different set of overloads to be selected. The key
     119// thing is that the name lookup is delayed to instantiation time.
     120template<typename T>
     121struct force_dependent_name_lookup
     122  : boost::mpl::false_ {};
     123
    115124template<class T>
    116125struct guid_initializer
    117126
     
    119128        // generates the statically-initialized objects whose constructors
    120129        // register the information allowing serialization of T objects
    121130        // through pointers to their base classes.
    122         instantiate_ptr_serialization((T*)0, 0);
     131        instantiate_ptr_serialization((T*)0,0,
     132                                      typename force_dependent_name_lookup<T>::type());
    123133        return *this;
    124134    }
    125135    const guid_initializer & export_guid(char const* key, mpl::true_){
     
    144154} // namespace archive
    145155} // namespace boost
    146156
     157// Internal macro: This macro
     158#define BOOST_SERIALIZATION_FORCE_DEP_NAME_LOOKUP(T)                    \
     159namespace boost { namespace archive { namespace detail {                \
     160template<> struct force_dependent_name_lookup<T> : public mpl::true_{}; \
     161}}}
     162
    147163#define BOOST_CLASS_EXPORT_GUID(T, K)                                               \
     164BOOST_SERIALIZATION_FORCE_DEP_NAME_LOOKUP(T)                                        \
    148165namespace                                                                           \
    149166{                                                                                   \
    150167    ::boost::archive::detail::guid_initializer< T > const &                         \
  • boost/archive/detail/register_archive.hpp

     
    44#ifndef BOOST_ARCHIVE_DETAIL_REGISTER_ARCHIVE_DWA2006521_HPP
    55# define BOOST_ARCHIVE_DETAIL_REGISTER_ARCHIVE_DWA2006521_HPP
    66
     7#include <boost/utility/enable_if.hpp>
     8
    79namespace boost { namespace archive { namespace detail {
    810
    911template <class Archive, class Serializable>
     
    1719struct _ptr_serialization_support
    1820  : ptr_serialization_support<Archive,Serializable>
    1921{
    20     typedef int type;
     22    typedef void type;
    2123};
    2224
    23 // This function gets called, but its only purpose is to participate
    24 // in overload resolution with the functions declared by
    25 // BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
    26 template <class Serializable>
    27 void instantiate_ptr_serialization(Serializable*, int) {}
     25template<typename Archive>
     26struct is_oarchive : public Archive::is_loading {};
    2827
    29 // The function declaration generated by this macro never actually
    30 // gets called, but its return type gets instantiated, and that's
    31 // enough to cause registration of serialization functions between
    32 // Archive and any exported Serializable type.  See also:
    33 // boost/serialization/export.hpp
     28// ADL causes _ptr_serialization_support to be instantiated for all
     29// archives that get registered. This function is actually called.
     30// See also: boost/serialization/export.hpp
    3431# define BOOST_SERIALIZATION_REGISTER_ARCHIVE(Archive)                  \
    3532namespace boost { namespace archive { namespace detail {                \
    3633                                                                        \
    3734template <class Serializable>                                           \
    38 typename _ptr_serialization_support<Archive, Serializable>::type        \
    39 instantiate_ptr_serialization( Serializable*, Archive* );               \
     35typename boost::enable_if<is_oarchive<Archive>,                         \
     36                          typename                                      \
     37                          _ptr_serialization_support<Archive,           \
     38                                                     Serializable>::type >::type \
     39instantiate_ptr_serialization( Serializable*,                           \
     40                               Archive*,                                \
     41                               boost::mpl::true_){}                     \
    4042                                                                        \
    4143}}}
    4244
  • libs/serialization/test/test_exported.cpp

     
    1818}
    1919#endif
    2020
     21#include <boost/serialization/export.hpp>
    2122#include <boost/serialization/base_object.hpp>
    2223#include <boost/serialization/type_info_implementation.hpp>
    2324#include <boost/archive/archive_exception.hpp>
    2425#include "test_tools.hpp"
    25 #include <boost/serialization/export.hpp>
    2626
    2727#include "base.hpp"
    2828