Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [jwalden@find-waldo-now tmp]$ cat amb.cpp
- #include <iostream>
- template<typename derived_t>
- struct protocol_object {};
- struct data_object : public protocol_object<data_object> {};
- struct conversion_required { conversion_required(int) {} };
- template<typename derived_t>
- void match_impl(protocol_object<derived_t> &value, int)
- {
- std::cout << "protocol_class";
- };
- template<typename T>
- void match_impl(T &value, conversion_required)
- {
- std::cout << "any other type";
- };
- template<typename T>
- void match(T& value)
- {
- return match_impl(value, 0);
- }
- int main()
- {
- data_object d;
- int i;
- match(d);
- match(i);
- }
- [jwalden@find-waldo-now tmp]$ g++48 -oamb amb.cpp
- amb.cpp: In instantiation of βvoid match(T&) [with T = data_object]β:
- amb.cpp:32:10: required from here
- amb.cpp:25:31: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [enabled by default]
- return match_impl(value, 0);
- ^
- amb.cpp:11:6: note: candidate 1: void match_impl(protocol_object<derived_t>&, int) [with derived_t = data_object]
- void match_impl(protocol_object<derived_t> &value, int)
- ^
- amb.cpp:17:6: note: candidate 2: void match_impl(T&, conversion_required) [with T = data_object]
- void match_impl(T &value, conversion_required)
- ^
- [jwalden@find-waldo-now tmp]$ clang++-tip -oamb amb.cpp
- amb.cpp:25:12: error: call to 'match_impl' is ambiguous
- return match_impl(value, 0);
- ^~~~~~~~~~
- amb.cpp:32:3: note: in instantiation of function template specialization 'match<data_object>' requested here
- match(d);
- ^
- amb.cpp:11:6: note: candidate function [with derived_t = data_object]
- void match_impl(protocol_object<derived_t> &value, int)
- ^
- amb.cpp:17:6: note: candidate function [with T = data_object]
- void match_impl(T &value, conversion_required)
- ^
- 1 error generated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement