blob: 0c9bacca3eddb915fb4f0faa1cce515a67aa286c [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Douglas Gregorfadb53b2011-03-12 01:48:56 +00002
Douglas Gregordb2eae62011-03-16 19:16:25 +00003namespace std {
4 class type_info {};
5}
6
7void one() { }
John McCall6dbba4f2011-10-11 23:14:30 +00008void two() { } // expected-note 4{{possible target for call}}
9void two(int) { } // expected-note 4{{possible target for call}}
Douglas Gregordb2eae62011-03-16 19:16:25 +000010
John McCall6dbba4f2011-10-11 23:14:30 +000011template<class T> void twoT() { } // expected-note 5{{possible target for call}}
12template<class T> void twoT(int) { } // expected-note 5{{possible target for call}}
Douglas Gregorfadb53b2011-03-12 01:48:56 +000013
14template<class T> void oneT() { }
15template<class T, class U> void oneT(U) { }
16/*
17The 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>
27template<void (*p)(int)> struct test { };
28
29int main()
30{
31 one; // expected-warning {{expression result unused}}
John McCall6dbba4f2011-10-11 23:14:30 +000032 two; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
Douglas Gregorfadb53b2011-03-12 01:48:56 +000033 oneT<int>; // expected-warning {{expression result unused}}
John McCall6dbba4f2011-10-11 23:14:30 +000034 twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
Douglas Gregordb2eae62011-03-16 19:16:25 +000035 typeid(oneT<int>); // expected-warning{{expression result unused}}
Douglas Gregorfadb53b2011-03-12 01:48:56 +000036 sizeof(oneT<int>); // expected-warning {{expression result unused}}
John McCall6dbba4f2011-10-11 23:14:30 +000037 sizeof(twoT<int>); //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
Douglas Gregorfadb53b2011-03-12 01:48:56 +000038 decltype(oneT<int>)* fun = 0;
39
40 *one; // expected-warning {{expression result unused}}
41 *oneT<int>; // expected-warning {{expression result unused}}
John McCall6dbba4f2011-10-11 23:14:30 +000042 *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 Blaikie2def7732011-12-09 21:42:37 +000044 !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 Gregorfadb53b2011-03-12 01:48:56 +000045 +oneT<int>; // expected-warning {{expression result unused}}
46 -oneT<int>; //expected-error {{invalid argument type}}
Chandler Carruthec8058f2011-08-17 09:34:37 +000047 oneT<int> == 0; // expected-warning {{equality comparison result unused}} \
48 // expected-note {{use '=' to turn this equality comparison into an assignment}}
49 0 == oneT<int>; // expected-warning {{equality comparison result unused}}
50 0 != oneT<int>; // expected-warning {{inequality comparison result unused}}
Douglas Gregorfadb53b2011-03-12 01:48:56 +000051 (false ? one : oneT<int>); // expected-warning {{expression result unused}}
52 void (*p1)(int); p1 = oneT<int>;
53
54 int i = (int) (false ? (void (*)(int))twoT<int> : oneT<int>); //expected-error {{incompatible operand}}
John McCall6dbba4f2011-10-11 23:14:30 +000055 (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 Blaikie2def7732011-12-09 21:42:37 +000056 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 Gregorfadb53b2011-03-12 01:48:56 +000057 void (*p)() = oneT<int>;
Douglas Gregordb2eae62011-03-16 19:16:25 +000058 test<oneT<int> > ti;
Douglas Gregorfadb53b2011-03-12 01:48:56 +000059 void (*u)(int) = oneT<int>;
60
61 b = (void (*)()) twoT<int>;
62
63 one < one; //expected-warning {{self-comparison always evaluates to false}} \
64 //expected-warning {{expression result unused}}
65
66 oneT<int> < oneT<int>; //expected-warning {{self-comparison always evaluates to false}} \
67 //expected-warning {{expression result unused}}
68
John McCall6dbba4f2011-10-11 23:14:30 +000069 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')}}
70 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 Carruthec8058f2011-08-17 09:34:37 +000071 oneT<int> == 0; // expected-warning {{equality comparison result unused}} \
72 // expected-note {{use '=' to turn this equality comparison into an assignment}}
Douglas Gregorfadb53b2011-03-12 01:48:56 +000073
74}
Douglas Gregordb2eae62011-03-16 19:16:25 +000075
76struct rdar9108698 {
77 template<typename> void f();
78};
79
80void test_rdar9108698(rdar9108698 x) {
John McCall6dbba4f2011-10-11 23:14:30 +000081 x.f<int>; // expected-error{{reference to non-static member function must be called}}
Douglas Gregordb2eae62011-03-16 19:16:25 +000082}