[Boost-bugs] [Boost C++ Libraries] #3875: make_shared, allocate_shared fail compile with aligned objects in msvc

Subject: [Boost-bugs] [Boost C++ Libraries] #3875: make_shared, allocate_shared fail compile with aligned objects in msvc
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-01-29 06:20:45


#3875: make_shared, allocate_shared fail compile with aligned objects in msvc
---------------------------------------------------------+------------------
 Reporter: Dieter Van Wassenhove <HyperOnyx@…> | Owner: pdimov
     Type: Bugs | Status: new
Milestone: Boost 1.42.0 | Component: smart_ptr
  Version: Boost 1.41.0 | Severity: Problem
 Keywords: allocate_shared msvc alignment |
---------------------------------------------------------+------------------
 When using make_shared or allocate_shared with a type that requires
 alignment, the code fails to compile in MSVC with an error similar to the
 following:

 error C2719: 'd': formal parameter with __declspec(align('64')) won't be
 aligned
 1>
 d:\projects\boost_1_41_0\boost\smart_ptr\detail\shared_count.hpp(124) :
 see reference to class template instantiation
 'boost::detail::sp_counted_impl_pd<P,D>' being compiled
 ............ (instantiation stack)

 Now, there is code in boost that looks like it wants to detect object
 alignment, but some how is not compatible with the MS compiler. There are
 various reports online indicating this is more of an issue with MS.
 However, when I provide my own custom allocator to boost::allocate_shared,
 I'd expect the issue to go away since both creation and destruction of the
 type would use my allocator and therefore not be concerned with the type's
 actual alignment any longer. I was hoping to work around this issue by
 providing an alignment sensitive allocator but I still get the same
 problem. It seems that the internal deleter is too overzealous in this
 situation and should be delegate the destruction of the object directly to
 the allocator.

 //repro: I didn't include a custom allocator as it seems fairly
 //straight forward to use any allocator and ensure that it's used //for
 destruction.

 #include <boost/shared_ptr.hpp>
 #include <boost/make_shared.hpp>


 struct __declspec(align(64)) MyClass
 {
         int x;
         float y;
         unsigned int z;
 };

 void main()
 {
         boost::shared_ptr<MyClass> ptr = boost::make_shared<MyClass>();
         ptr->x = 6;
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3875>
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:02 UTC