Menu

#57 uniqueLessThanCompareFn::operator() is non-const

v1.0 (example)
open
nobody
None
5
5 days ago
5 days ago
Caleb Xu
No

With some newer libc++ implementations, the std::set comparator is required to be callable on a const object. The uniqueLessThanCompareFn::operator() is non-const, leading to compilation failures.

  /Library/Developer/CommandLineTools/SDKs/MacOSX27.sdk/usr/include/c++/v1/__utility/lazy_synth_three_way_comparator.h:45:21: error: no matching function for call to object of type 'const UniqueNodesResult::uniqueLessThanCompareFn'
     45 |     bool __result = __comp_(__lhs_, __rhs_);
        |                     ^~~~~~~
  /Library/Developer/CommandLineTools/SDKs/MacOSX27.sdk/usr/include/c++/v1/__tree:1868:20: note: in instantiation of member function 'std::__lazy_compare_result<UniqueNodesResult::uniqueLessThanCompareFn, RefCountPointer<const Node>, RefCountPointer<const Node>>::__less' requested here
   1868 |     if (__comp_res.__less()) {
        |                    ^
  /Library/Developer/CommandLineTools/SDKs/MacOSX27.sdk/usr/include/c++/v1/__tree:1039:38: note: in instantiation of function template specialization 'std::__tree<RefCountPointer<const Node>, UniqueNodesResult::uniqueLessThanCompareFn, std::allocator<RefCountPointer<const Node>>>::__find_equal<RefCountPointer<const Node>>' requested here
   1039 |           auto [__parent, __child] = __find_equal(__key);
        |                                      ^
  /Library/Developer/CommandLineTools/SDKs/MacOSX27.sdk/usr/include/c++/v1/set:760:20: note: in instantiation of function template specialization 'std::__tree<RefCountPointer<const Node>, UniqueNodesResult::uniqueLessThanCompareFn, std::allocator<RefCountPointer<const Node>>>::__emplace_unique<RefCountPointer<const Node>>' requested here
    760 |     return __tree_.__emplace_unique(std::move(__v));
        |                    ^
  src/ast/XQDocumentOrder.cpp:104:16: note: in instantiation of member function 'std::set<RefCountPointer<const Node>, UniqueNodesResult::uniqueLessThanCompareFn>::insert' requested here
    104 |                   if(noDups_.insert(result).second) break;
        |                              ^
  ./include/xqilla/ast/XQDocumentOrder.hpp:71:10: note: candidate function not viable: 'this' argument has type 'const UniqueNodesResult::uniqueLessThanCompareFn', but method is not marked const
     71 |     bool operator()(const Node::Ptr &first, const Node::Ptr &second)
        |          ^

The implementation itself is already const-compatible, the method just hasn't been marked as such; therefore the fix is as simple as marking the method as const.

1 Attachments

Discussion


Log in to post a comment.