Boost C++ Libraries: Ticket #13275: flat_map's allocator_type constructor could potentially produce invalid output in optimization https://svn.boost.org/trac10/ticket/13275 <p> In class flat_map, we have constructor: </p> <pre class="wiki">BOOST_CONTAINER_FORCEINLINE explicit flat_map(const allocator_type&amp; a) : m_flat_tree(container_detail::force&lt;const impl_allocator_type&gt;(a)) {} </pre><p> This could cause a problem. </p> <p> Impl_allocator_type is </p> <pre class="wiki">typedef typename impl_tree_t::allocator_type impl_allocator_type; </pre><p> And impl_tree_t is </p> <pre class="wiki">typedef container_detail::flat_tree&lt; container_detail::pair&lt;Key, T&gt;, container_detail::select1st&lt;Key&gt;, Compare, typename allocator_traits&lt;Allocator&gt;::template portable_rebind_alloc &lt;container_detail::pair&lt;Key, T&gt; &gt;::type&gt; impl_tree_t; </pre><p> container_detail::force() is doing an reinterpret_cast essentially. Let's say argument a is </p> <pre class="wiki">allocator&lt; std::pair&lt;Key, T&gt; &gt; </pre><p> Then if we are calling that constructor, we are actually reinterpret_cast argument 'a' from </p> <pre class="wiki">allocator&lt; std::pair&lt;Key, T&gt; &gt; </pre><p> to </p> <pre class="wiki">allocator&lt; container_detail::pair&lt;Key, T&gt; &gt; </pre><p> While the program could run fine in no-opt because <strong>std::pair</strong> and<strong> container_detail::pair</strong> could be very similar and swappable, the program could produce invalid result when compiler turn on optimization. Compiler would find no alias information between <strong>allocator&lt;std::pair&lt;Key, T&gt;&gt;</strong> and <strong>allocator&lt;container_detail::pair&lt;Key, T&gt;&gt;</strong>, and think they are not related and move things around to produce invalid result. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13275 Trac 1.4.3 Kohei Takahashi Fri, 27 Oct 2017 11:18:19 GMT component changed; owner set https://svn.boost.org/trac10/ticket/13275#comment:1 https://svn.boost.org/trac10/ticket/13275#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Ion Gaztañaga</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">container</span> </li> </ul> Ticket