overload-candidates.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T>
  3. const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}}
  4. void test_min() {
  5. (void)min(1, 2l); // expected-error{{no matching function for call to 'min'}}
  6. }
  7. template<typename R, typename T>
  8. R *dyn_cast(const T&); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}}
  9. void test_dyn_cast(int* ptr) {
  10. (void)dyn_cast(ptr); // expected-error{{no matching function for call to 'dyn_cast'}}
  11. }
  12. template<int I, typename T>
  13. void get(const T&); // expected-note{{candidate template ignored: invalid explicitly-specified argument for template parameter 'I'}}
  14. template<template<class T> class, typename T>
  15. void get(const T&); // expected-note{{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
  16. void test_get(void *ptr) {
  17. get<int>(ptr); // expected-error{{no matching function for call to 'get'}}
  18. }
  19. template<typename T>
  20. typename T::type get_type(const T&); // expected-note{{candidate template ignored: substitution failure [with T = int *]: type 'int *' cannot be used prior to '::'}}
  21. template<typename T>
  22. void get_type(T *, int[(int)sizeof(T) - 9] = 0); // expected-note{{candidate template ignored: substitution failure [with T = int]: array size is negative}}
  23. void test_get_type(int *ptr) {
  24. (void)get_type(ptr); // expected-error{{no matching function for call to 'get_type'}}
  25. }
  26. struct X {
  27. template<typename T>
  28. const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}}
  29. };
  30. void test_X_min(X x) {
  31. (void)x.min(1, 2l); // expected-error{{no matching member function for call to 'min'}}
  32. }
  33. namespace boost {
  34. template<bool, typename = void> struct enable_if {};
  35. template<typename T> struct enable_if<true, T> { typedef T type; };
  36. }
  37. template<typename T> typename boost::enable_if<sizeof(T) == 4, int>::type if_size_4(); // expected-note{{candidate template ignored: disabled by 'enable_if' [with T = char]}}
  38. int k = if_size_4<char>(); // expected-error{{no matching function}}
  39. namespace llvm {
  40. template<typename Cond, typename T = void> struct enable_if : boost::enable_if<Cond::value, T> {};
  41. }
  42. template<typename T> struct is_int { enum { value = false }; };
  43. template<> struct is_int<int> { enum { value = true }; };
  44. template<typename T> typename llvm::enable_if<is_int<T> >::type if_int(); // expected-note{{candidate template ignored: disabled by 'enable_if' [with T = char]}}
  45. void test_if_int() {
  46. if_int<char>(); // expected-error{{no matching function}}
  47. }
  48. template<typename T> struct NonTemplateFunction {
  49. typename boost::enable_if<sizeof(T) == 4, int>::type f(); // expected-error{{no type named 'type' in 'boost::enable_if<false, int>'; 'enable_if' cannot be used to disable this declaration}}
  50. };
  51. NonTemplateFunction<char> NTFC; // expected-note{{here}}
  52. namespace NS1 {
  53. template <class A>
  54. class array {};
  55. }
  56. namespace NS2 {
  57. template <class A>
  58. class array {};
  59. }
  60. template <class A>
  61. void foo(NS2::array<A>); // expected-note{{candidate template ignored: could not match 'NS2::array' against 'NS1::array'}}
  62. void test() {
  63. foo(NS1::array<int>()); // expected-error{{no matching function for call to 'foo'}}
  64. }
  65. namespace std {
  66. template<bool, typename = void> struct enable_if {};
  67. template<typename T> struct enable_if<true, T> { typedef T type; };
  68. template<typename T, T V> struct integral_constant { static const T value = V; };
  69. typedef integral_constant<bool, false> false_type;
  70. typedef integral_constant<bool, true> true_type;
  71. };
  72. namespace PR15673 {
  73. template<typename T>
  74. struct a_trait : std::false_type {};
  75. template<typename T,
  76. typename Requires = typename std::enable_if<a_trait<T>::value>::type> // expected-warning {{C++11 extension}}
  77. // expected-note@-1 {{candidate template ignored: disabled by 'enable_if' [with T = int]}}
  78. void foo() {}
  79. void bar() { foo<int>(); } // expected-error {{no matching function for call to 'foo'}}
  80. template<typename T>
  81. struct some_trait : std::false_type {};
  82. // FIXME: It would be nice to tunnel the 'disabled by enable_if' diagnostic through here.
  83. template<typename T>
  84. struct a_pony : std::enable_if<some_trait<T>::value> {};
  85. template<typename T,
  86. typename Requires = typename a_pony<T>::type> // expected-warning {{C++11 extension}}
  87. // FIXME: The source location here is poor.
  88. void baz() { } // expected-note {{candidate template ignored: substitution failure [with T = int]: no type named 'type' in 'PR15673::a_pony<int>'}}
  89. void quux() { baz<int>(); } // expected-error {{no matching function for call to 'baz'}}
  90. // FIXME: This note doesn't make it clear which candidate we rejected.
  91. template <typename T>
  92. using unicorns = typename std::enable_if<some_trait<T>::value>::type; // expected-warning {{C++11 extension}}
  93. // expected-note@-1 {{candidate template ignored: disabled by 'enable_if' [with T = int]}}
  94. template<typename T,
  95. typename Requires = unicorns<T> > // expected-warning {{C++11 extension}}
  96. void wibble() {}
  97. void wobble() { wibble<int>(); } // expected-error {{no matching function for call to 'wibble'}}
  98. }