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