File: resolve-single-template-id.cpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (104 lines) | stat: -rw-r--r-- 6,027 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s

namespace std {
  class type_info {};
}

void one() { }
void two() { } // expected-note 4{{possible target for call}}
void two(int) { } // expected-note 4{{possible target for call}}

template<class T> void twoT() { } // expected-note 5{{possible target for call}}
template<class T> void twoT(int) { } // expected-note 5{{possible target for call}}

template<class T> void oneT() { }
template<class T, class U> void oneT(U) { }
/*
The target can be
 an object or reference being initialized (8.5, 8.5.3),
 the left side of an assignment (5.17),
 a parameter of a function (5.2.2),
 a parameter of a user-defined operator (13.5),
 the return value of a function, operator function, or conversion (6.6.3),
 an explicit type conversion (5.2.3, 5.2.9, 5.4), or
 a non-type template-parameter (14.3.2)
*/
//#include <typeinfo>
template<void (*p)(int)> struct test { };

int main()
{
   one;         // expected-warning {{expression result unused}}
   two;         // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
   oneT<int>;  // expected-warning {{expression result unused}}
   twoT<int>;  // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
   typeid(oneT<int>); // expected-warning{{expression result unused}}
  sizeof(oneT<int>); // expected-error {{invalid application of 'sizeof' to a function type}}
  sizeof(twoT<int>); //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
  decltype(oneT<int>)* fun = 0;
  
  *one;    // expected-warning {{expression result unused}}
  *oneT<int>;   // expected-warning {{expression result unused}}
  *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}}
  *twoT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
  !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}}
  +oneT<int>;  // expected-warning {{expression result unused}}
  -oneT<int>;  //expected-error {{invalid argument type}}
  oneT<int> == 0;   // expected-warning {{equality comparison result unused}} \
                    // expected-note {{use '=' to turn this equality comparison into an assignment}} \
                    // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
                    // expected-note {{prefix with the address-of operator to silence this warning}}
  0 == oneT<int>;   // expected-warning {{equality comparison result unused}} \
                    // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
                    // expected-note {{prefix with the address-of operator to silence this warning}}
  0 != oneT<int>;   // expected-warning {{inequality comparison result unused}} \
                    // expected-warning {{comparison of function 'oneT<int>' not equal to a null pointer is always true}} \
                    // expected-note {{prefix with the address-of operator to silence this warning}}
  (false ? one : oneT<int>);   // expected-warning {{expression result unused}}
  void (*p1)(int); p1 = oneT<int>;
  
  int i = (int) (false ? (void (*)(int))twoT<int> : oneT<int>); //expected-error {{incompatible operand}}
  (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}}
  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}}
  void (*p)() = oneT<int>;
  test<oneT<int> > ti;
  void (*u)(int) = oneT<int>;

  b = (void (*)()) twoT<int>;

  one < one; // expected-warning {{self-comparison always evaluates to false}} \
             // expected-warning {{relational comparison result unused}}       \
             // expected-warning {{ordered comparison of function pointers}}

  oneT<int> < oneT<int>; // expected-warning {{self-comparison always evaluates to false}} \
                         // expected-warning {{relational comparison result unused}}       \
                         // expected-warning {{ordered comparison of function pointers}}

  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')}}
  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}}
  oneT<int> == 0;   // expected-warning {{equality comparison result unused}} \
                    // expected-note {{use '=' to turn this equality comparison into an assignment}} \
                    // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
                    // expected-note {{prefix with the address-of operator to silence this warning}}

}

struct rdar9108698 {
  template<typename> void f(); // expected-note{{possible target for call}}
};

void test_rdar9108698(rdar9108698 x) {
  x.f<int>; // expected-error{{reference to non-static member function must be called}}
}

namespace GCC_PR67898 {
  void f(int);
  void f(float);
  template<typename T, T F, T G, bool b = F == G> struct X {
    static_assert(b, "");
  };
  template<typename T> void test1() { X<void(T), f, f>(); }
  template<typename T> void test2() { X<void(*)(T), f, f>(); }
  template void test1<int>();
  template void test2<int>();
}