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