xref: /aosp_15_r20/external/clang/test/SemaTemplate/instantiate-function-params.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple i686-unknown-unknown -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li // PR6619
4*67e74705SXin Li template<bool C> struct if_c { };
5*67e74705SXin Li template<typename T1> struct if_ {
6*67e74705SXin Li   typedef if_c< static_cast<bool>(T1::value)> almost_type_; // expected-note 5{{in instantiation}}
7*67e74705SXin Li };
8*67e74705SXin Li template <class Model, void (Model::*)()> struct wrap_constraints { };
9*67e74705SXin Li template <class Model>
10*67e74705SXin Li inline char has_constraints_(Model* , // expected-note 3{{candidate template ignored}}
11*67e74705SXin Li                                wrap_constraints<Model,&Model::constraints>* = 0); // expected-note 2{{in instantiation}}
12*67e74705SXin Li 
13*67e74705SXin Li template <class Model> struct not_satisfied {
14*67e74705SXin Li   static const bool value = sizeof( has_constraints_((Model*)0)  == 1); // expected-error 3{{no matching function}} \
15*67e74705SXin Li   // expected-note 2{{while substituting deduced template arguments into function template 'has_constraints_' [with }}
16*67e74705SXin Li };
17*67e74705SXin Li template <class ModelFn> struct requirement_;
18*67e74705SXin Li template <void(*)()> struct instantiate {
19*67e74705SXin Li };
20*67e74705SXin Li template <class Model> struct requirement_<void(*)(Model)>                           : if_<       not_satisfied<Model>         >::type { // expected-note 5{{in instantiation}}
21*67e74705SXin Li };
22*67e74705SXin Li template <class Model> struct usage_requirements {
23*67e74705SXin Li };
24*67e74705SXin Li template < typename TT > struct InputIterator                            {
25*67e74705SXin Li     typedef  instantiate< & requirement_<void(*)(usage_requirements<InputIterator> x)>::failed> boost_concept_check1; // expected-note {{in instantiation}}
26*67e74705SXin Li };
27*67e74705SXin Li template < typename TT > struct ForwardIterator                              : InputIterator<TT>                              { // expected-note {{in instantiation}}
28*67e74705SXin Li   typedef instantiate< & requirement_<void(*)(usage_requirements<ForwardIterator> x)>::failed> boost_concept_check2; // expected-note {{in instantiation}}
29*67e74705SXin Li 
30*67e74705SXin Li };
31*67e74705SXin Li typedef instantiate< &requirement_<void(*)(ForwardIterator<char*> x)>::failed> boost_concept_checkX;// expected-note 3{{in instantiation}}
32*67e74705SXin Li 
33*67e74705SXin Li template<typename T> struct X0 { };
34*67e74705SXin Li template<typename R, typename A1> struct X0<R(A1 param)> { };
35*67e74705SXin Li 
36*67e74705SXin Li template<typename T, typename A1, typename A2>
instF0(X0<T (A1)> x0a,X0<T (A2)> x0b)37*67e74705SXin Li void instF0(X0<T(A1)> x0a, X0<T(A2)> x0b) {
38*67e74705SXin Li   X0<T(A1)> x0c;
39*67e74705SXin Li   X0<T(A2)> x0d;
40*67e74705SXin Li }
41*67e74705SXin Li 
42*67e74705SXin Li template void instF0<int, int, float>(X0<int(int)>, X0<int(float)>);
43*67e74705SXin Li 
44*67e74705SXin Li template<typename R, typename A1, R (*ptr)(A1)> struct FuncPtr { };
45*67e74705SXin Li template<typename A1, int (*ptr)(A1)> struct FuncPtr<int, A1, ptr> { };
46*67e74705SXin Li 
47*67e74705SXin Li template<typename R, typename A1> R unary_func(A1);
48*67e74705SXin Li 
49*67e74705SXin Li template<typename R, typename A1, typename A2>
use_func_ptr()50*67e74705SXin Li void use_func_ptr() {
51*67e74705SXin Li   FuncPtr<R, A1, &unary_func<R, A1> > fp1;
52*67e74705SXin Li   FuncPtr<R, A2, &unary_func<R, A2> > fp2;
53*67e74705SXin Li };
54*67e74705SXin Li 
55*67e74705SXin Li template void use_func_ptr<int, float, double>();
56*67e74705SXin Li 
57*67e74705SXin Li namespace PR6990 {
58*67e74705SXin Li   template < typename , typename = int, typename = int > struct X1;
59*67e74705SXin Li   template <typename >
60*67e74705SXin Li   struct X2;
61*67e74705SXin Li 
62*67e74705SXin Li   template <typename = int *, typename TokenT = int,
63*67e74705SXin Li             typename = int( X2<TokenT> &)>
64*67e74705SXin Li   struct X3
65*67e74705SXin Li   {
66*67e74705SXin Li   };
67*67e74705SXin Li 
68*67e74705SXin Li   template <typename , typename P>
69*67e74705SXin Li   struct X3_base : X3< X1<int, P> >
70*67e74705SXin Li   {
71*67e74705SXin Li   protected: typedef X1< P> type;
72*67e74705SXin Li     X3<type> e;
73*67e74705SXin Li   };
74*67e74705SXin Li 
75*67e74705SXin Li   struct r : X3_base<int, int>
76*67e74705SXin Li   {
77*67e74705SXin Li   };
78*67e74705SXin Li }
79*67e74705SXin Li 
80*67e74705SXin Li namespace InstantiateFunctionTypedef {
81*67e74705SXin Li   template<typename T>
82*67e74705SXin Li   struct X {
83*67e74705SXin Li     typedef int functype(int, int);
84*67e74705SXin Li     functype func1;
85*67e74705SXin Li     __attribute__((noreturn)) functype func2;
86*67e74705SXin Li 
87*67e74705SXin Li     typedef int stdfunctype(int, int) __attribute__((stdcall));
88*67e74705SXin Li     __attribute__((stdcall)) functype stdfunc1;
89*67e74705SXin Li     stdfunctype stdfunc2;
90*67e74705SXin Li 
91*67e74705SXin Li     __attribute__((pcs("aapcs"))) functype pcsfunc; // expected-warning {{calling convention 'pcs' ignored for this target}}
92*67e74705SXin Li   };
93*67e74705SXin Li 
f(X<int> x)94*67e74705SXin Li   void f(X<int> x) {
95*67e74705SXin Li     (void)x.func1(1, 2);
96*67e74705SXin Li     (void)x.func2(1, 2);
97*67e74705SXin Li     (void)x.stdfunc1(1, 2);
98*67e74705SXin Li     (void)x.stdfunc2(1, 2);
99*67e74705SXin Li     (void)x.pcsfunc(1, 2);
100*67e74705SXin Li   }
101*67e74705SXin Li }
102