resolve-single-template-id.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. namespace std {
  3. class type_info {};
  4. }
  5. void one() { }
  6. void two() { } // expected-note 4{{possible target for call}}
  7. void two(int) { } // expected-note 4{{possible target for call}}
  8. template<class T> void twoT() { } // expected-note 5{{possible target for call}}
  9. template<class T> void twoT(int) { } // expected-note 5{{possible target for call}}
  10. template<class T> void oneT() { }
  11. template<class T, class U> void oneT(U) { }
  12. /*
  13. The target can be
  14. an object or reference being initialized (8.5, 8.5.3),
  15. the left side of an assignment (5.17),
  16. a parameter of a function (5.2.2),
  17. a parameter of a user-defined operator (13.5),
  18. the return value of a function, operator function, or conversion (6.6.3),
  19. an explicit type conversion (5.2.3, 5.2.9, 5.4), or
  20. a non-type template-parameter (14.3.2)
  21. */
  22. //#include <typeinfo>
  23. template<void (*p)(int)> struct test { };
  24. int main()
  25. {
  26. one; // expected-warning {{expression result unused}}
  27. two; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
  28. oneT<int>; // expected-warning {{expression result unused}}
  29. twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
  30. typeid(oneT<int>); // expected-warning{{expression result unused}}
  31. sizeof(oneT<int>); // expected-error {{invalid application of 'sizeof' to a function type}}
  32. sizeof(twoT<int>); //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
  33. decltype(oneT<int>)* fun = 0;
  34. *one; // expected-warning {{expression result unused}}
  35. *oneT<int>; // expected-warning {{expression result unused}}
  36. *two; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{indirection requires pointer operand}}
  37. *twoT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
  38. !oneT<int>; // expected-warning {{expression result unused}} expected-warning {{address of function 'oneT<int>' will always evaluate to 'true'}} expected-note {{prefix with the address-of operator to silence this warning}}
  39. +oneT<int>; // expected-warning {{expression result unused}}
  40. -oneT<int>; //expected-error {{invalid argument type}}
  41. oneT<int> == 0; // expected-warning {{equality comparison result unused}} \
  42. // expected-note {{use '=' to turn this equality comparison into an assignment}} \
  43. // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
  44. // expected-note {{prefix with the address-of operator to silence this warning}}
  45. 0 == oneT<int>; // expected-warning {{equality comparison result unused}} \
  46. // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
  47. // expected-note {{prefix with the address-of operator to silence this warning}}
  48. 0 != oneT<int>; // expected-warning {{inequality comparison result unused}} \
  49. // expected-warning {{comparison of function 'oneT<int>' not equal to a null pointer is always true}} \
  50. // expected-note {{prefix with the address-of operator to silence this warning}}
  51. (false ? one : oneT<int>); // expected-warning {{expression result unused}}
  52. void (*p1)(int); p1 = oneT<int>;
  53. int i = (int) (false ? (void (*)(int))twoT<int> : oneT<int>); //expected-error {{incompatible operand}}
  54. (twoT<int>) == oneT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
  55. bool b = oneT<int>; // expected-warning {{address of function 'oneT<int>' will always evaluate to 'true'}} expected-note {{prefix with the address-of operator to silence this warning}}
  56. void (*p)() = oneT<int>;
  57. test<oneT<int> > ti;
  58. void (*u)(int) = oneT<int>;
  59. b = (void (*)()) twoT<int>;
  60. one < one; //expected-warning {{self-comparison always evaluates to false}} \
  61. //expected-warning {{relational comparison result unused}}
  62. oneT<int> < oneT<int>; //expected-warning {{self-comparison always evaluates to false}} \
  63. //expected-warning {{relational comparison result unused}}
  64. two < two; //expected-error 2 {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{invalid operands to binary expression ('void' and 'void')}}
  65. twoT<int> < twoT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
  66. oneT<int> == 0; // expected-warning {{equality comparison result unused}} \
  67. // expected-note {{use '=' to turn this equality comparison into an assignment}} \
  68. // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
  69. // expected-note {{prefix with the address-of operator to silence this warning}}
  70. }
  71. struct rdar9108698 {
  72. template<typename> void f(); // expected-note{{possible target for call}}
  73. };
  74. void test_rdar9108698(rdar9108698 x) {
  75. x.f<int>; // expected-error{{reference to non-static member function must be called}}
  76. }