Debian Codegraph @

clang/test/SemaTemplate/instantiate-template-template-parm.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
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;
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'}}
21
22 // Template template parameters
23 template<int> struct B;
24
25 template<typename T,
26 template<T Value> class X> // expected-error{{cannot have type 'float'}}
27 struct X0 { };
28
29 X0<int, B> x0b1;
30 X0<float, B> x0b2; // expected-note{{while substituting}}
31 X0<long, B> x0b3;
32
33 template<template<int V> class TT>
34 struct X1 { };
35
36 template<typename T, template<T V> class TT>
37 struct X2 {
38 X1<TT> x1;
39 };
40
41 template<int V> struct X3i { };
42 template<long V> struct X3l { };
43
44 X2<int, X3i> x2okay;
45 X2<long, X3l> x2okay2;
46
47 template <typename T, template <T, T> class TT, class R = TT<1, 2> >
48 struct Comp {
49 typedef R r1;
50 template <T x, T y> struct gt {
51 static const bool result = x > y;
52 };
53 typedef gt<2, 1> r2;
54 };
55
56 template <int x, int y> struct lt {
57 static const bool result = x < y;
58 };
59
60 Comp<int, lt> c0;
61
62 namespace PR8629 {
63 template<template<int> class TT> struct X0
64 {
65 static void apply();
66 };
67 template<int> struct Type { };
68
69 template<class T> struct X1
70 {
71 template<class U> struct Inner;
72
73 template<class U> void g()
74 {
75 typedef Inner<U> Init;
76 X0<Init::template VeryInner>::apply();
77 }
78 template<int N> void f ()
79 {
80 g<Type<N> >();
81 }
82 };
83 template<class T> template<class U> struct X1<T>::Inner
84 {
85 template<int> struct VeryInner {
86 };
87 };
88 struct X1Container
89 {
90 X1Container()
91 {
92 simplex_.f<0>();
93 }
94 X1<double> simplex_;
95 };
96 }