<div class="gmail_extra">Sorry, don't know why this email went directly to Matthieu instead of the list...<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Ovanes Markaryan</b> <span dir="ltr"><<a href="mailto:om_clang@keywallet.com">om_clang@keywallet.com</a>></span><br>

Date: Mon, Apr 23, 2012 at 10:30 PM<br>Subject: Re: [cfe-dev] [libc++] possible bug?<br>To: Matthieu Monrocq <<a href="mailto:matthieu.monrocq@gmail.com">matthieu.monrocq@gmail.com</a>><br><br><br><div class="gmail_extra">

Hello Matthieu,</div><div class="gmail_extra"><br></div><div class="gmail_extra">please see my answers below.<br><br><div class="gmail_quote"><div class="im">On Mon, Apr 23, 2012 at 6:53 PM, Matthieu Monrocq <span dir="ltr"><<a href="mailto:matthieu.monrocq@gmail.com" target="_blank">matthieu.monrocq@gmail.com</a>></span> wrote:<br>


</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="im"><br><br><div class="gmail_quote">Le 22 avril 2012 23:58, Ovanes Markaryan <span dir="ltr"><<a href="mailto:om_clang@keywallet.com" target="_blank">om_clang@keywallet.com</a>></span> a écrit :<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br><br><div class="gmail_quote"><div>On Sun, Apr 22, 2012 at 11:32 PM, Marc Glisse <span dir="ltr"><<a href="mailto:marc.glisse@inria.fr" target="_blank">marc.glisse@inria.fr</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>On Sun, 22 Apr 2012, Ovanes Markaryan wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello *,<br>
just tried to compile SYMPHONY-5.4.4 with clang 3.0 + libc++ (tag 31). While<br>
compiling it I receive this error:<br>
<br>
include/c++/v1/algorithm:643:<u></u>97: error: invalid operands to binary<br>
expression<br>
      ('const reducedCost' and 'const reducedCost')<br>
    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1&<br>
__y) const {return __x < __y;}<br>
</blockquote>
<br></div>
[...]<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    bool operator<(const reducedCost & other)<br>
</blockquote>
<br></div>
Missing const here. It is often preferable to avoid making operators member functions when you can avoid it.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    {<br>
        return (value>other.value);<br>
    }<span><font color="#888888"><br>
</font></span></blockquote><span><font color="#888888">
<br>
-- <br>
Marc Glisse<br></font></span></blockquote><div><br></div></div><div>Hello Marc,</div><div><br></div><div>you are definitely right. I overlooked it, since as already wrote this is not my code (just copy pasted it from the lib)... But in my tests I commented out this operator< and provided the specialization of  std::less, to just test it and it failed as well. I did not test with both enable (operator< and less-specialization). Actually this code is somehow really bad, because less is actually not less but greater ;) This code compiles fine with gcc and clang + gcc's version of stdlib. As far as I remember the standard requires that std::less is specialized to allow the less comparison or the operator< is implicitly used through the generalized less. In my tests less specialization was not considered by make_heap. This is my point.</div>





<div><br></div><div><br></div></div></div></div></blockquote></div></div><div class="im">Two questions:<br><br>1. Does it work if you actually specify that `operator<` is `const` ?<br></div></div></blockquote><div> yes.</div>

<div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_extra"><br>2. Did you were careful about putting the specialization of `less` (for this class) before its first use ? (it is not clear from your example)<br></div></blockquote></div><div>Yes. Please the attached file. </div>

<div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra">
<br>If you could, for example, provide a simple attachment that reproduces the issue it would be slightly simpler to investigate.</div></blockquote><div><br></div></div><div>Here we go:</div><div><br></div><div>#include <algorithm></div>


<div>#include <iterator></div><div>#include <functional></div><div class="im"><div><br></div><div>struct reducedCost</div><div>{</div><div>    /** To avoid computing two times the same row direction will have strange</div>

<div>
     values, direction is -1 or 1 if for only one of the two direction</div><div>     rc is <0 and is -2 or 2 if the two direction have one <0 rc with the sign</div><div>     indicating which one of the two directions is the best.<br></div>


<div>     Note that by theory only one reduced cost (for u_i, or v_i)</div><div>     maybe negative for each direction.</div><div>     */</div><div>    int direction;</div><div>    /** gammSign is the sign of gamma (corresponding to taking rc for u_i or v_i)</div>


<div>     for the best of the two rc for this row.*/</div><div>    int gammaSign;</div><div>    /** gammaSign2 is the sign of gamma for the worst of the two rc for this row.*/</div><div>    int gammaSign2;</div><div>    /** if both reduced costs are <0 value is the smallest of the two.*/</div>


<div>    double value;</div><div>    /** greatest of the two reduced costs */</div><div>    double value2;</div><div>    /** index of the row.*/</div><div>    int row;</div></div><div>#ifdef TEST_WITH_OPLESS_CONST</div><div>

    bool operator<(const reducedCost & other)const</div>
<div>    {</div><div>        return (value>other.value);</div><div>    }</div><div>#endif</div><div>};</div><div><br></div><div>#ifdef TEST_WITH_LESS_SPEC</div><div class="im"><div>namespace std</div><div>{</div><div>

    template<></div>
<div>    struct less<reducedCost></div><div>        : ::std::binary_function<reducedCost, reducedCost, bool></div><div>    {</div><div>        bool operator()(const reducedCost & lhs, const reducedCost & rhs)const</div>


<div>        {</div><div>            return lhs.value>rhs.value;</div><div>        }</div><div>    };</div><div>}</div></div><div>#endif</div><div class="im"><div><br></div><div>int main()</div><div>{</div><div>  reducedCost r[100]={};</div>


<div><br></div><div>  std::make_heap(&r[0], &r[0]+100);</div><div>  return 0;</div><div>};</div><div><br></div><div> </div></div><div>I compiled it with clang 3.0 and libc++ taged with release_31. Here the both command lines:</div>


<div>This will fail</div><div>$ ~/toolsets/clang-3.0/bin/clang++ -DTEST_WITH_LESS_SPEC=1 -stdlib=libc++ -I/home/ovanes/toolsets/clang-3.0/include/c++/v1  -L/home/ovanes/toolsets/clang-3.0/lib make_heap_test.cpp</div><div>


This works:</div><div>$ ~/toolsets/clang-3.0/bin/clang++ -DTEST_WITH_OPLESS_CONST=1 -stdlib=libc++ -I/home/ovanes/toolsets/clang-3.0/include/c++/v1  -L/home/ovanes/toolsets/clang-3.0/lib make_heap_test.cpp</div><div><br>

</div>
<div>Regards,</div><div>Ovanes</div><div><br></div></div><br></div>
</div><br></div>