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