Boost C++ Libraries: Ticket #3875: make_shared, allocate_shared fail compile with aligned objects in msvc https://svn.boost.org/trac10/ticket/3875 <p> 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: </p> <p> error C2719: 'd': formal parameter with <span class="underline">declspec(align('64')) won't be aligned 1&gt; 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&lt;P,D&gt;' being compiled ............ (instantiation stack) </span></p> <p> 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. </p> <p> <em>repro: I didn't include a custom allocator as it seems fairly </em>straight forward to use any allocator and ensure that it's used <em>for destruction. </em></p> <p> #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/make_shared.hpp&gt; </p> <p> struct <span class="underline">declspec(align(64)) <a class="missing wiki">MyClass</a> { </span></p> <blockquote> <p> int x; float y; unsigned int z; </p> </blockquote> <p> }; </p> <p> void main() { </p> <blockquote> <p> boost::shared_ptr&lt;<a class="missing wiki">MyClass</a>&gt; ptr = boost::make_shared&lt;<a class="missing wiki">MyClass</a>&gt;(); ptr-&gt;x = 6; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3875 Trac 1.4.3 Steven Watanabe Sat, 27 Mar 2010 05:56:33 GMT <link>https://svn.boost.org/trac10/ticket/3875#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3875#comment:1</guid> <description> <p> <a class="ext-link" href="http://lists.boost.org/boost-users/2010/03/57713.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2010/03/57713.php</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 24 Feb 2011 21:51:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3875#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3875#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/69250" title="Fix make_shared to not copy the deleter. Refs #4256. Refs #3875.">[69250]</a>) Fix make_shared to not copy the deleter. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4256" title="#4256: Bugs: boost::make_shared() may issue stack overflow while constructing large ... (closed: fixed)">#4256</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3875" title="#3875: Bugs: make_shared, allocate_shared fail compile with aligned objects in msvc (closed: fixed)">#3875</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 24 Feb 2011 21:53:53 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/3875#comment:3 https://svn.boost.org/trac10/ticket/3875#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Peter Dimov Tue, 22 Mar 2011 23:38:15 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3875#comment:4 https://svn.boost.org/trac10/ticket/3875#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70436" title="Merge [69250] to release. Fixes #4256. Fixes #3875.">[70436]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/69250" title="Fix make_shared to not copy the deleter. Refs #4256. Refs #3875.">[69250]</a> to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4256" title="#4256: Bugs: boost::make_shared() may issue stack overflow while constructing large ... (closed: fixed)">#4256</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3875" title="#3875: Bugs: make_shared, allocate_shared fail compile with aligned objects in msvc (closed: fixed)">#3875</a>. </p> Ticket