Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#243 librt: Make brep_hit's operator overloads const.

Incomplete
closed-fixed
Sean Morrison
None
5
2014-03-02
2013-10-27
No

When building BRL-CAD with libc++ instead of libstdc++, brep.cpp fails to compile with an error similar to this:

[ 54%] Building CXX object src/librt/CMakeFiles/librt.dir/primitives/brep/brep.cpp.o
In file included from /s/brlcad/src/librt/primitives/brep/brep.cpp:31:
In file included from /usr/include/c++/v1/vector:261:
In file included from /usr/include/c++/v1/__bit_reference:15:
/usr/include/c++/v1/algorithm:678:97: error: invalid operands to binary expression ('const brep_hit' and 'const brep_hit')
    _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
                                                                                            ~~~ ^ ~~~
/usr/include/c++/v1/list:2170:13: note: in instantiation of member function 'std::__1::__less<brep_hit, brep_hit>::operator()' requested here
        if (__comp(*--__e2, *__f1))
            ^
/usr/include/c++/v1/list:2156:5: note: in instantiation of function template specialization 'std::__1::list<brep_hit, std::__1::allocator<brep_hit> >::__sort<std::__1::__less<brep_hit, brep_hit> >' requested here
    __sort(begin(), end(), base::__sz(), __comp);
    ^
/usr/include/c++/v1/list:2147:5: note: in instantiation of function template specialization 'std::__1::list<brep_hit, std::__1::allocator<brep_hit> >::sort<std::__1::__less<brep_hit, brep_hit> >' requested here
    sort(__less<value_type>());
    ^
/s/brlcad/src/librt/primitives/brep/brep.cpp:1158:10: note: in instantiation of member function 'std::__1::list<brep_hit, std::__1::allocator<brep_hit> >::sort' requested here
    hits.sort();
         ^
/s/brlcad/src/librt/primitives/brep/brep.cpp:545:10: note: candidate function not viable: 'this' argument has type 'const brep_hit', but method is not marked const
    bool operator<(const brep_hit& h)
         ^

This happens because brep_hit's operator<() is non-const. Since neither operator<() nor operator==() change the class' state it should be fine to make both of them const.

1 Attachments

Discussion

  • Sean Morrison
    Sean Morrison
    2014-02-24

    • status: open --> closed-fixed
    • assigned_to: Sean Morrison