xref: /aosp_15_r20/external/clang/test/SemaTemplate/instantiate-overload-candidates.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // This is the function actually selected during overload resolution, and the
4*67e74705SXin Li // only one defined.
f(T *,int)5*67e74705SXin Li template <typename T> void f(T*, int) {}
6*67e74705SXin Li 
7*67e74705SXin Li template <typename T> struct S;
8*67e74705SXin Li template <typename T> struct S_ : S<T> { typedef int type; }; // expected-note{{in instantiation}}
9*67e74705SXin Li template <typename T> struct S {
10*67e74705SXin Li   // Force T to have a complete type here so we can observe instantiations with
11*67e74705SXin Li   // incomplete types.
12*67e74705SXin Li   T t; // expected-error{{field has incomplete type}}
13*67e74705SXin Li };
14*67e74705SXin Li 
15*67e74705SXin Li // Provide a bad class and an overload that instantiates templates with it.
16*67e74705SXin Li class NoDefinition; // expected-note{{forward declaration}}
17*67e74705SXin Li template <typename T> S_<NoDefinition>::type f(T*, NoDefinition*); // expected-note{{in instantiation}}
18*67e74705SXin Li 
test(int x)19*67e74705SXin Li void test(int x) {
20*67e74705SXin Li   f(&x, 0);
21*67e74705SXin Li }
22*67e74705SXin Li 
23*67e74705SXin Li // Ensure that we instantiate an overloaded function if it's selected by
24*67e74705SXin Li // overload resolution when initializing a function pointer.
25*67e74705SXin Li template<typename T> struct X {
fX26*67e74705SXin Li   static T f() { T::error; } // expected-error {{has no members}}
27*67e74705SXin Li   static T f(bool);
28*67e74705SXin Li };
29*67e74705SXin Li void (*p)() = &X<void>::f; // expected-note {{instantiation of}}
30*67e74705SXin Li 
31*67e74705SXin Li namespace PR13098 {
32*67e74705SXin Li   struct A {
33*67e74705SXin Li     A(int);
operator ++PR13098::A34*67e74705SXin Li     void operator++() {}
operator +PR13098::A35*67e74705SXin Li     void operator+(int) {}
operator +PR13098::A36*67e74705SXin Li     void operator+(A) {}
operator []PR13098::A37*67e74705SXin Li     void operator[](int) {}
operator []PR13098::A38*67e74705SXin Li     void operator[](A) {}
39*67e74705SXin Li   };
40*67e74705SXin Li   struct B : A {
41*67e74705SXin Li     using A::operator++;
42*67e74705SXin Li     using A::operator+;
43*67e74705SXin Li     using A::operator[];
44*67e74705SXin Li   };
f(B b)45*67e74705SXin Li   template<typename T> void f(B b) {
46*67e74705SXin Li     ++b;
47*67e74705SXin Li     b + 0;
48*67e74705SXin Li     b[0];
49*67e74705SXin Li   }
50*67e74705SXin Li   template void f<void>(B);
51*67e74705SXin Li }
52