Boost C++ Libraries: Ticket #9501: interval_set uses std::set with non strict weak ordering https://svn.boost.org/trac10/ticket/9501 <p> This program fails with clang's own LLVM STL implementation (libc++) </p> <p> #include &lt;boost/icl/interval_set.hpp&gt; void t1() { </p> <blockquote> <p> <em>correct output: </em>[15 43) </p> </blockquote> <p> </p> <blockquote> <p> <em>invalid output (mac, xcode 5.0.2, w/standard lib: "libc++ (LLVM)") </em>[15 31) <em>[30 43) </em></p> </blockquote> <p> </p> <blockquote> <p> typedef boost::icl::interval_set&lt;int&gt; IVS; typedef boost::icl::discrete_interval&lt;int&gt; IV; </p> </blockquote> <blockquote> <p> IVS ivs; ivs.insert(IV(20, 21)); ivs.insert(IV(30, 43)); ivs.insert(IV(15, 31)); </p> </blockquote> <p> </p> <blockquote> <p> for(auto it = ivs.begin(); it != ivs.end(); ++it) </p> <blockquote> <p> printf("[%d %d)\n", it-&gt;lower(), it-&gt;upper()); </p> </blockquote> </blockquote> <p> } </p> <p> Reason: </p> <p> interval_set's underlying std::set container requires a strict weak ordering. interval_set uses an "overlap-free less" (icl/detail/exclusive_less_than.hpp) which is not strict weak (that is, !(a&lt;b)&amp;&amp;!(b&lt;a) is not transitive). Therefore, behaviour of std::set::insert becomes undefined. With clang's libc++, it is different than the one excepted by the icl. </p> <p> std::set test case mimicking what's happening under the hood in interval_set::insert: </p> <p> struct MIV { </p> <blockquote> <p> MIV(int a, int b) :lo(a), hi(b) {} </p> </blockquote> <p> </p> <blockquote> <p> int lo, hi; </p> </blockquote> <p> </p> <blockquote> <p> <em>equivalent to the intervalset's overlap-free less </em>in boost::icl::exclusive_less_than bool operator&lt;(const MIV&amp; y) const { </p> <blockquote> <p> return hi &lt;= y.lo; </p> </blockquote> <p> } </p> </blockquote> <p> }; </p> <p> #include &lt;set&gt; void t2() { </p> <blockquote> <p> <em>output when icl works: </em>it: [30-43), bool: 0 </p> </blockquote> <blockquote> <p> <em>output when icl fails (mac, xcode 5.0.2, w/standard lib: "libc++ (LLVM)") </em>it: [20-21), bool: 0 </p> </blockquote> <blockquote> <p> typedef std::set&lt;MIV&gt; MSET; MSET ms; </p> </blockquote> <p> </p> <blockquote> <p> ms.insert(MIV(20, 21)); ms.insert(MIV(30, 43)); </p> </blockquote> <p> </p> <blockquote> <p> auto itb = ms.insert(MIV(15, 31)); </p> </blockquote> <p> </p> <blockquote> <p> printf("it: [%d-%d), bool: %d\n", itb.first-&gt;lo, itb.first-&gt;hi, itb.second); </p> </blockquote> <p> </p> <blockquote> <p> } </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9501 Trac 1.4.3 Tamás Kenéz <tamas.kenez@…> Tue, 17 Dec 2013 11:04:37 GMT cc set https://svn.boost.org/trac10/ticket/9501#comment:1 https://svn.boost.org/trac10/ticket/9501#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">tamas.kenez@…</span> added </li> </ul> Ticket Ivan Romanenko <viva.cpp@…> Thu, 16 Jan 2014 15:26:39 GMT <link>https://svn.boost.org/trac10/ticket/9501#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9501#comment:2</guid> <description> <p> Also found the same problem. When ICL use boost::container::flat_set instead of std::set. </p> <p> Because implementation of insertion algorithm in boost::container::flat_set differs with std::set and boost::container::set. </p> <p> PS. Same problem with interval_map and std::map </p> </description> <category>Ticket</category> </item> <item> <author>tvk.boost@…</author> <pubDate>Wed, 18 Jun 2014 15:51:58 GMT</pubDate> <title>severity changed https://svn.boost.org/trac10/ticket/9501#comment:3 https://svn.boost.org/trac10/ticket/9501#comment:3 <ul> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Showstopper</span> </li> </ul> <p> I can reproduce the problem with clang/libc++. </p> <p> A temporary workaround is to </p> <pre class="wiki">#define ICL_USE_BOOST_MOVE_IMPLEMENTATION </pre><p> before including ICL headers. This will make it use the boost implementation std::set. </p> Ticket Joachim Faulhaber Tue, 01 Sep 2015 10:13:36 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9501#comment:4 https://svn.boost.org/trac10/ticket/9501#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed with 1.56.0 </p> Ticket