Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 2 | template<template<typename T> class MetaFun, typename Value> |
| 3 | struct apply { |
| 4 | typedef typename MetaFun<Value>::type type; |
| 5 | }; |
| 6 | |
| 7 | template<class T> |
| 8 | struct add_pointer { |
| 9 | typedef T* type; |
| 10 | }; |
| 11 | |
| 12 | template<class T> |
| 13 | struct add_reference { |
| 14 | typedef T& type; |
| 15 | }; |
| 16 | |
| 17 | int i; |
| 18 | apply<add_pointer, int>::type ip = &i; |
| 19 | apply<add_reference, int>::type ir = i; |
Douglas Gregor | 52bb5d2 | 2009-12-16 16:54:16 +0000 | [diff] [blame] | 20 | 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'}} |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 21 | |
| 22 | // Template template parameters |
| 23 | template<int> struct B; // expected-note{{has a different type 'int'}} |
| 24 | |
| 25 | template<typename T, |
| 26 | template<T Value> class X> // expected-error{{cannot have type 'float'}} \ |
| 27 | // expected-note{{with type 'long'}} |
| 28 | struct X0 { }; |
| 29 | |
| 30 | X0<int, B> x0b1; |
| 31 | X0<float, B> x0b2; // expected-note{{while substituting}} |
| 32 | X0<long, B> x0b3; // expected-error{{template template argument has different template parameters}} |
Douglas Gregor | fb898e1 | 2009-11-12 16:20:59 +0000 | [diff] [blame] | 33 | |
| 34 | template<template<int V> class TT> // expected-note{{parameter with type 'int'}} |
| 35 | struct X1 { }; |
| 36 | |
| 37 | template<typename T, template<T V> class TT> |
| 38 | struct X2 { |
| 39 | X1<TT> x1; // expected-error{{has different template parameters}} |
| 40 | }; |
| 41 | |
| 42 | template<int V> struct X3i { }; |
| 43 | template<long V> struct X3l { }; // expected-note{{different type 'long'}} |
| 44 | |
| 45 | X2<int, X3i> x2okay; |
| 46 | X2<long, X3l> x2bad; // expected-note{{instantiation}} |