Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 2 | |
Douglas Gregor | db2eae6 | 2011-03-16 19:16:25 +0000 | [diff] [blame] | 3 | namespace std { |
| 4 | class type_info {}; |
| 5 | } |
| 6 | |
| 7 | void one() { } |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 8 | void two() { } // expected-note 4{{possible target for call}} |
| 9 | void two(int) { } // expected-note 4{{possible target for call}} |
Douglas Gregor | db2eae6 | 2011-03-16 19:16:25 +0000 | [diff] [blame] | 10 | |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 11 | template<class T> void twoT() { } // expected-note 5{{possible target for call}} |
| 12 | template<class T> void twoT(int) { } // expected-note 5{{possible target for call}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 13 | |
| 14 | template<class T> void oneT() { } |
| 15 | template<class T, class U> void oneT(U) { } |
| 16 | /* |
| 17 | The target can be |
| 18 | an object or reference being initialized (8.5, 8.5.3), |
| 19 | the left side of an assignment (5.17), |
| 20 | a parameter of a function (5.2.2), |
| 21 | a parameter of a user-defined operator (13.5), |
| 22 | the return value of a function, operator function, or conversion (6.6.3), |
| 23 | an explicit type conversion (5.2.3, 5.2.9, 5.4), or |
| 24 | a non-type template-parameter (14.3.2) |
| 25 | */ |
| 26 | //#include <typeinfo> |
| 27 | template<void (*p)(int)> struct test { }; |
| 28 | |
| 29 | int main() |
| 30 | { |
| 31 | one; // expected-warning {{expression result unused}} |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 32 | two; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 33 | oneT<int>; // expected-warning {{expression result unused}} |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 34 | twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} |
Douglas Gregor | db2eae6 | 2011-03-16 19:16:25 +0000 | [diff] [blame] | 35 | typeid(oneT<int>); // expected-warning{{expression result unused}} |
Eli Friedman | c99b90e | 2013-08-13 22:26:42 +0000 | [diff] [blame] | 36 | sizeof(oneT<int>); // expected-error {{invalid application of 'sizeof' to a function type}} |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 37 | sizeof(twoT<int>); //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 38 | decltype(oneT<int>)* fun = 0; |
| 39 | |
| 40 | *one; // expected-warning {{expression result unused}} |
| 41 | *oneT<int>; // expected-warning {{expression result unused}} |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 42 | *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}} |
| 43 | *twoT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} |
David Blaikie | 2def773 | 2011-12-09 21:42:37 +0000 | [diff] [blame] | 44 | !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}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 45 | +oneT<int>; // expected-warning {{expression result unused}} |
| 46 | -oneT<int>; //expected-error {{invalid argument type}} |
Chandler Carruth | ec8058f | 2011-08-17 09:34:37 +0000 | [diff] [blame] | 47 | oneT<int> == 0; // expected-warning {{equality comparison result unused}} \ |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 48 | // expected-note {{use '=' to turn this equality comparison into an assignment}} \ |
| 49 | // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \ |
| 50 | // expected-note {{prefix with the address-of operator to silence this warning}} |
| 51 | 0 == oneT<int>; // expected-warning {{equality comparison result unused}} \ |
| 52 | // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \ |
| 53 | // expected-note {{prefix with the address-of operator to silence this warning}} |
| 54 | 0 != oneT<int>; // expected-warning {{inequality comparison result unused}} \ |
| 55 | // expected-warning {{comparison of function 'oneT<int>' not equal to a null pointer is always true}} \ |
| 56 | // expected-note {{prefix with the address-of operator to silence this warning}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 57 | (false ? one : oneT<int>); // expected-warning {{expression result unused}} |
| 58 | void (*p1)(int); p1 = oneT<int>; |
| 59 | |
| 60 | int i = (int) (false ? (void (*)(int))twoT<int> : oneT<int>); //expected-error {{incompatible operand}} |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 61 | (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}} |
David Blaikie | 2def773 | 2011-12-09 21:42:37 +0000 | [diff] [blame] | 62 | 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}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 63 | void (*p)() = oneT<int>; |
Douglas Gregor | db2eae6 | 2011-03-16 19:16:25 +0000 | [diff] [blame] | 64 | test<oneT<int> > ti; |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 65 | void (*u)(int) = oneT<int>; |
| 66 | |
| 67 | b = (void (*)()) twoT<int>; |
| 68 | |
| 69 | one < one; //expected-warning {{self-comparison always evaluates to false}} \ |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 70 | //expected-warning {{relational comparison result unused}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 71 | |
| 72 | oneT<int> < oneT<int>; //expected-warning {{self-comparison always evaluates to false}} \ |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 73 | //expected-warning {{relational comparison result unused}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 74 | |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 75 | 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')}} |
| 76 | 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}} |
Chandler Carruth | ec8058f | 2011-08-17 09:34:37 +0000 | [diff] [blame] | 77 | oneT<int> == 0; // expected-warning {{equality comparison result unused}} \ |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 78 | // expected-note {{use '=' to turn this equality comparison into an assignment}} \ |
| 79 | // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \ |
| 80 | // expected-note {{prefix with the address-of operator to silence this warning}} |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 81 | |
| 82 | } |
Douglas Gregor | db2eae6 | 2011-03-16 19:16:25 +0000 | [diff] [blame] | 83 | |
| 84 | struct rdar9108698 { |
David Blaikie | c2fe818 | 2013-06-04 00:28:46 +0000 | [diff] [blame] | 85 | template<typename> void f(); // expected-note{{possible target for call}} |
Douglas Gregor | db2eae6 | 2011-03-16 19:16:25 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | void test_rdar9108698(rdar9108698 x) { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 89 | x.f<int>; // expected-error{{reference to non-static member function must be called}} |
Douglas Gregor | db2eae6 | 2011-03-16 19:16:25 +0000 | [diff] [blame] | 90 | } |