Opened 13 years ago

Closed 12 years ago

#3875 closed Bugs (fixed)

make_shared, allocate_shared fail compile with aligned objects in msvc

Reported by: Dieter Van Wassenhove <HyperOnyx@…> Owned by: Peter Dimov
Milestone: Boost 1.42.0 Component: smart_ptr
Version: Boost 1.41.0 Severity: Problem
Keywords: allocate_shared msvc alignment Cc:

Description

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;

}

Change History (4)

comment:2 by Peter Dimov, 12 years ago

(In [69250]) Fix make_shared to not copy the deleter. Refs #4256. Refs #3875.

comment:3 by Peter Dimov, 12 years ago

Status: newassigned

comment:4 by Peter Dimov, 12 years ago

Resolution: fixed
Status: assignedclosed

(In [70436]) Merge [69250] to release. Fixes #4256. Fixes #3875.

Note: See TracTickets for help on using tickets.