Re: [Boost-bugs] [Boost C++ Libraries] #4370: [Serialization] map with private default constructor does not compile

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4370: [Serialization] map with private default constructor does not compile
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-06-17 16:40:03


#4370: [Serialization] map with private default constructor does not compile
---------------------------+------------------------------------------------
  Reporter: anonymous | Owner: ramey
      Type: Bugs | Status: closed
 Milestone: Boost 1.44.0 | Component: serialization
   Version: Boost 1.40.0 | Severity: Problem
Resolution: wontfix | Keywords:
---------------------------+------------------------------------------------

Comment (by boost@…):

 Replying to [comment:5 ramey]:

> I do indeed get a compiler error on the following line
>
> std::map<int,A>::value_type m1(1,A(10));
>
> which I'm not really understanding as you point out shouldn't be
 instantitiating the default constructor. In any case, that's an MSVC
 and/or standard library issue.

 Robert, we've also seen this. It is indeed MSVC getting confused,
 resulting in it thinking a default constructed pair must be required.

 However, it IS triggered by the attempt to serialize a std::pair where at
 least one of the arguments has a private default ctor. This can be seen
 by commenting out lines 60 and 65 (as they appear in trac) in the OP's
 test.cpp.

> So ... what do you want me to do? Do you have a patch to submit?

 Because the key or value type of the std::pair will (typically) have been
 given friend access to boost::serialization::access, it is annoying that
 the pair trips up. However, the following appears to be a suitable patch
 (unless I've missed something):

 // Add to boost/serialization/utility.hpp:

 template <typename Archive, typename First, typename Second>
 void load_construct_data(Archive & ar, std::pair<First, Second> * t,
 unsigned int const)
 {
     typedef BOOST_DEDUCED_TYPENAME remove_const<First>::type
 NonConstFirst;
     NonConstFirst &first = const_cast<NonConstFirst&>(t->first);
     access::construct(&first);
     access::construct(&t->second);
 }

 ///////////////

 I.e. instead of invoking the default ctor of std::pair<>, route through
 boost::serialization::access to in-place construct the two values.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4370#comment:8>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC