xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/issue150.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc // expected-no-diagnostics
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc // Core issue 150: Template template parameters and default arguments
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc template<typename T, typename U>
7*f4a2713aSLionel Sambuc struct is_same {
8*f4a2713aSLionel Sambuc   static const bool value = false;
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc template<typename T>
12*f4a2713aSLionel Sambuc struct is_same<T, T> {
13*f4a2713aSLionel Sambuc   static const bool value = true;
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc namespace PR9353 {
17*f4a2713aSLionel Sambuc   template<class _T, class Traits> class IM;
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc   template <class T, class Trt,
20*f4a2713aSLionel Sambuc             template<class _T, class Traits = int> class IntervalMap>
foo(IntervalMap<T,Trt> * m)21*f4a2713aSLionel Sambuc   void foo(IntervalMap<T,Trt>* m) { typedef IntervalMap<int> type; }
22*f4a2713aSLionel Sambuc 
f(IM<int,int> * m)23*f4a2713aSLionel Sambuc   void f(IM<int, int>* m) { foo(m); }
24*f4a2713aSLionel Sambuc }
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc namespace PR9400 {
27*f4a2713aSLionel Sambuc   template<template <typename T, typename = T > class U> struct A
28*f4a2713aSLionel Sambuc   {
29*f4a2713aSLionel Sambuc     template<int> U<int> foo();
30*f4a2713aSLionel Sambuc   };
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc   template <typename T, typename = T>
33*f4a2713aSLionel Sambuc   struct s {
34*f4a2713aSLionel Sambuc   };
35*f4a2713aSLionel Sambuc 
f()36*f4a2713aSLionel Sambuc   void f() {
37*f4a2713aSLionel Sambuc     A<s> x;
38*f4a2713aSLionel Sambuc     x.foo<2>();
39*f4a2713aSLionel Sambuc   }
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc namespace MultiReplace {
43*f4a2713aSLionel Sambuc   template<typename Z,
44*f4a2713aSLionel Sambuc            template<typename T, typename U = T *, typename V = U const> class TT>
45*f4a2713aSLionel Sambuc   struct X {
46*f4a2713aSLionel Sambuc     typedef TT<Z> type;
47*f4a2713aSLionel Sambuc   };
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc   template<typename T, typename = int, typename = float>
50*f4a2713aSLionel Sambuc   struct Y { };
51*f4a2713aSLionel Sambuc 
52*f4a2713aSLionel Sambuc   int check0[is_same<X<int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1];
53*f4a2713aSLionel Sambuc }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc namespace MultiReplacePartial {
56*f4a2713aSLionel Sambuc   template<typename First, typename Z,
57*f4a2713aSLionel Sambuc            template<typename T, typename U = T *, typename V = U const> class TT>
58*f4a2713aSLionel Sambuc   struct X {
59*f4a2713aSLionel Sambuc     typedef TT<Z> type;
60*f4a2713aSLionel Sambuc   };
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc   template<typename Z,
63*f4a2713aSLionel Sambuc            template<typename T, typename U = T *, typename V = U const> class TT>
64*f4a2713aSLionel Sambuc   struct X<int, Z, TT> {
65*f4a2713aSLionel Sambuc     typedef TT<Z> type;
66*f4a2713aSLionel Sambuc   };
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc   template<typename T, typename = int, typename = float>
69*f4a2713aSLionel Sambuc   struct Y { };
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc   int check0[is_same<X<int, int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1];
72*f4a2713aSLionel Sambuc }
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc namespace PR9016 {
75*f4a2713aSLionel Sambuc   template<typename > struct allocator ;
76*f4a2713aSLionel Sambuc   template<typename > struct less ;
77*f4a2713aSLionel Sambuc 
78*f4a2713aSLionel Sambuc   template<class T, template<class> class Compare, class Default,
79*f4a2713aSLionel Sambuc            template<class> class Alloc>
80*f4a2713aSLionel Sambuc   struct interval_set { };
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc   template <class X, template<class> class = less> struct interval_type_default {
83*f4a2713aSLionel Sambuc     typedef X type;
84*f4a2713aSLionel Sambuc   };
85*f4a2713aSLionel Sambuc 
86*f4a2713aSLionel Sambuc   template <class T,
87*f4a2713aSLionel Sambuc             template<class _T, template<class> class Compare = PR9016::less,
88*f4a2713aSLionel Sambuc                      class = typename interval_type_default<_T,Compare>::type,
89*f4a2713aSLionel Sambuc                      template<class> class = allocator> class IntervalSet>
90*f4a2713aSLionel Sambuc   struct ZZZ
91*f4a2713aSLionel Sambuc   {
92*f4a2713aSLionel Sambuc     IntervalSet<T> IntervalSetT;
93*f4a2713aSLionel Sambuc   };
94*f4a2713aSLionel Sambuc 
95*f4a2713aSLionel Sambuc   template <class T,
96*f4a2713aSLionel Sambuc             template<class _T, template<class> class Compare = PR9016::less,
97*f4a2713aSLionel Sambuc                      class = typename interval_type_default<_T,Compare>::type,
98*f4a2713aSLionel Sambuc                      template<class> class = allocator> class IntervalSet>
int40()99*f4a2713aSLionel Sambuc   void int40()
100*f4a2713aSLionel Sambuc   {
101*f4a2713aSLionel Sambuc     IntervalSet<T> IntervalSetT;
102*f4a2713aSLionel Sambuc   }
103*f4a2713aSLionel Sambuc 
test()104*f4a2713aSLionel Sambuc   void test() {
105*f4a2713aSLionel Sambuc     ZZZ<int, interval_set> zzz;
106*f4a2713aSLionel Sambuc     int40<int, interval_set>();
107*f4a2713aSLionel Sambuc   }
108*f4a2713aSLionel Sambuc }
109