Possible Duplicate:
Clang, std::shared_ptr and std::less/operator<
So yeah, the title is pretty much the whole problem. As you can see from the snippet below i did implement operator< so i have no idea of what’s going on.
Here is the code:
namespace {
struct Transition {
string name;
StatePtr toState;
Transition(string s = string(), StatePtr state = nullptr)
: name(move(s))
, toState(move(state))
{}
friend bool operator==(Transition const& lhs, Transition const & rhs) {
return lhs.name == rhs.name && lhs.toState == rhs.toState;
}
friend bool operator<(Transition const & lhs, Transition const & rhs);
};
struct State {
string name;
set<TransitionPtr> transitions;
explicit State(string s = string())
: name(move(s))
{}
void addTransition(string s, StatePtr sp = nullptr){
TransitionPtr new_t = make_transition(s, sp);
for(auto& t : transitions){
if(t == new_t){
return;
}
}
transitions.insert(move(new_t)); // This is where the error happens.
}
};
}
bool operator<(StateMachine::Transition const & lhs, StateMachine::Transition const & rhs) {
return lhs.toState.get() < rhs.toState.get();
}
and the error message is:
In file included from ../llvm_opt_pass/cgd.cpp:3:
In file included from /srv/scratch/sigubufo/clang/stable/3.1_src/llvm/include/llvm/Instructions.h:23:
In file included from /srv/scratch/sigubufo/clang/stable/3.1_src/llvm/include/llvm/ADT/ArrayRef.h:13:
In file included from /srv/scratch/sigubufo/clang/stable/3.1_src/llvm/include/llvm/ADT/SmallVector.h:24:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/memory:85:
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/unique_ptr.h:486:14: error: no matching function for call to object of type ‘std::less<_CT>’
return std::less<_CT>()(__x.get(), __y.get());
^~~~~~~~~~~~~~~~/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_function.h:237:20: note: in instantiation of function template specialization ‘std::operator<<::StateMachine::Transition, std::default_delete<::StateMachine::Transition>, ::StateMachine::Transition, std::default_delete<::StateMachine::Transition> >’ requested here
{ return __x < __y; }
^/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_tree.h:1285:13: note: in instantiation of member function ‘std::less::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > >::operator()’ requested here
__comp = _M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__x));
^/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_set.h:424:9: note: > in instantiation of function template specialization ‘std::_Rb_tree::StateMachine::Transition, std::default_delete<::StateMachine::Transition> >, std::unique_ptr<::StateMachine::Transition, std::default_delete<::StateMachine::Transition> >, std::_Identity::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > >, std::less::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > >, std::allocator::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > > ::_M_insert_unique::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > >’ requested here
_M_t._M_insert_unique(std::move(__x));
^../llvm_opt_pass/cgd.cpp:72:17: note: in instantiation of member function ‘std::set::StateMachine::Transition, std::default_delete<::StateMachine::Transition> >, std::less::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > >, std::allocator::StateMachine::Transition, std::default_delete<::StateMachine::Transition> > > >::insert’ requested here
transitions.insert(move(new_t));
^/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/bits/stl_function.h:236:7: note: candidate function not viable: no known conversion from ‘pointer’ (aka ‘::StateMachine::Transition *’) to ‘::StateMachine::Transition *&&&’ > for 1st argument;
operator()(const _Tp& __x, const _Tp& __y) const
Ok, so the solution is the same as to this question: Clang, std::shared_ptr and std::less/operator< .
Basically it’s a bug in type_traits from libstdc++.