temp_func_order.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T>
  3. int &f0(T);
  4. template<typename T>
  5. float &f0(T*);
  6. void test_f0(int i, int *ip) {
  7. int &ir = f0(i);
  8. float &fr = f0(ip);
  9. }
  10. template<typename T, typename U>
  11. int &f1(T, U);
  12. template<typename T>
  13. float &f1(T, T);
  14. void test_f1(int i, float f) {
  15. int &ir = f1(i, f);
  16. float &fr1 = f1(i, i);
  17. float &fr2 = f1(f, f);
  18. }
  19. template<typename T, typename U>
  20. struct A { };
  21. template<typename T>
  22. int &f2(T);
  23. template<typename T, typename U>
  24. float &f2(A<T, U>);
  25. template<typename T>
  26. double &f2(A<T, T>);
  27. void test_f2(int i, A<int, float> aif, A<int, int> aii) {
  28. int &ir = f2(i);
  29. float &fr = f2(aif);
  30. double &dr = f2(aii);
  31. }
  32. template<typename T, typename U>
  33. int &f3(T*, U); // expected-note{{candidate}}
  34. template<typename T, typename U>
  35. float &f3(T, U*); // expected-note{{candidate}}
  36. void test_f3(int i, int *ip, float *fp) {
  37. int &ir = f3(ip, i);
  38. float &fr = f3(i, fp);
  39. f3(ip, ip); // expected-error{{ambiguous}}
  40. }
  41. template<typename T>
  42. int &f4(T&);
  43. template<typename T>
  44. float &f4(const T&);
  45. void test_f4(int i, const int ic) {
  46. int &ir1 = f4(i);
  47. float &fr1 = f4(ic);
  48. }
  49. template<typename T, typename U>
  50. int &f5(T&, const U&); // expected-note{{candidate}}
  51. template<typename T, typename U>
  52. float &f5(const T&, U&); // expected-note{{candidate}}
  53. void test_f5(int i, const int ic) {
  54. f5(i, i); // expected-error{{ambiguous}}
  55. }
  56. template<typename T, typename U>
  57. int &f6(T&, U&);
  58. template<typename T, typename U>
  59. float &f6(const T&, U&);
  60. void test_f6(int i, const int ic) {
  61. int &ir = f6(i, i);
  62. float &fr = f6(ic, ic);
  63. }
  64. struct CrazyFun {
  65. template<typename T, typename U> operator A<T, U>();
  66. template<typename T> operator A<T, T>();
  67. };
  68. void fun(CrazyFun cf) {
  69. A<int, float> aif = cf;
  70. A<int, int> aii = cf;
  71. }