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