xref: /aosp_15_r20/external/clang/test/SemaTemplate/instantiate-template-template-parm.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li template<template<typename T> class MetaFun, typename Value>
3*67e74705SXin Li struct apply {
4*67e74705SXin Li   typedef typename MetaFun<Value>::type type;
5*67e74705SXin Li };
6*67e74705SXin Li 
7*67e74705SXin Li template<class T>
8*67e74705SXin Li struct add_pointer {
9*67e74705SXin Li   typedef T* type;
10*67e74705SXin Li };
11*67e74705SXin Li 
12*67e74705SXin Li template<class T>
13*67e74705SXin Li struct add_reference {
14*67e74705SXin Li   typedef T& type;
15*67e74705SXin Li };
16*67e74705SXin Li 
17*67e74705SXin Li int i;
18*67e74705SXin Li apply<add_pointer, int>::type ip = &i;
19*67e74705SXin Li apply<add_reference, int>::type ir = i;
20*67e74705SXin Li apply<add_reference, float>::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}}
21*67e74705SXin Li 
22*67e74705SXin Li // Template template parameters
23*67e74705SXin Li template<int> struct B; // expected-note{{has a different type 'int'}}
24*67e74705SXin Li 
25*67e74705SXin Li template<typename T,
26*67e74705SXin Li          template<T Value> class X> // expected-error{{cannot have type 'float'}} \
27*67e74705SXin Li                                     // expected-note{{with type 'long'}}
28*67e74705SXin Li struct X0 { };
29*67e74705SXin Li 
30*67e74705SXin Li X0<int, B> x0b1;
31*67e74705SXin Li X0<float, B> x0b2; // expected-note{{while substituting}}
32*67e74705SXin Li X0<long, B> x0b3; // expected-error{{template template argument has different template parameters}}
33*67e74705SXin Li 
34*67e74705SXin Li template<template<int V> class TT> // expected-note{{parameter with type 'int'}}
35*67e74705SXin Li struct X1 { };
36*67e74705SXin Li 
37*67e74705SXin Li template<typename T, template<T V> class TT>
38*67e74705SXin Li struct X2 {
39*67e74705SXin Li   X1<TT> x1; // expected-error{{has different template parameters}}
40*67e74705SXin Li };
41*67e74705SXin Li 
42*67e74705SXin Li template<int V> struct X3i { };
43*67e74705SXin Li template<long V> struct X3l { }; // expected-note{{different type 'long'}}
44*67e74705SXin Li 
45*67e74705SXin Li X2<int, X3i> x2okay;
46*67e74705SXin Li X2<long, X3l> x2bad; // expected-note{{instantiation}}
47*67e74705SXin Li 
48*67e74705SXin Li template <typename T, template <T, T> class TT, class R = TT<1, 2> >
49*67e74705SXin Li struct Comp {
50*67e74705SXin Li   typedef R r1;
51*67e74705SXin Li   template <T x, T y> struct gt {
52*67e74705SXin Li     static const bool result = x > y;
53*67e74705SXin Li   };
54*67e74705SXin Li   typedef gt<2, 1> r2;
55*67e74705SXin Li };
56*67e74705SXin Li 
57*67e74705SXin Li template <int x, int y> struct lt {
58*67e74705SXin Li   static const bool result = x < y;
59*67e74705SXin Li };
60*67e74705SXin Li 
61*67e74705SXin Li Comp<int, lt> c0;
62*67e74705SXin Li 
63*67e74705SXin Li namespace PR8629 {
64*67e74705SXin Li   template<template<int> class TT> struct X0
65*67e74705SXin Li   {
66*67e74705SXin Li     static void apply();
67*67e74705SXin Li   };
68*67e74705SXin Li   template<int> struct Type { };
69*67e74705SXin Li 
70*67e74705SXin Li   template<class T> struct X1
71*67e74705SXin Li   {
72*67e74705SXin Li     template<class U> struct Inner;
73*67e74705SXin Li 
gPR8629::X174*67e74705SXin Li     template<class U> void g()
75*67e74705SXin Li     {
76*67e74705SXin Li       typedef Inner<U> Init;
77*67e74705SXin Li       X0<Init::template VeryInner>::apply();
78*67e74705SXin Li     }
fPR8629::X179*67e74705SXin Li     template<int N> void f ()
80*67e74705SXin Li     {
81*67e74705SXin Li       g<Type<N> >();
82*67e74705SXin Li     }
83*67e74705SXin Li   };
84*67e74705SXin Li   template<class T> template<class U> struct X1<T>::Inner
85*67e74705SXin Li   {
86*67e74705SXin Li     template<int> struct VeryInner {
87*67e74705SXin Li     };
88*67e74705SXin Li   };
89*67e74705SXin Li   struct X1Container
90*67e74705SXin Li   {
X1ContainerPR8629::X1Container91*67e74705SXin Li     X1Container()
92*67e74705SXin Li     {
93*67e74705SXin Li       simplex_.f<0>();
94*67e74705SXin Li     }
95*67e74705SXin Li     X1<double> simplex_;
96*67e74705SXin Li   };
97*67e74705SXin Li }
98