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