annotate clang/test/SemaTemplate/instantiate-template-template-parm.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2 template<template<typename T> class MetaFun, typename Value>
anatofuz
parents:
diff changeset
3 struct apply {
anatofuz
parents:
diff changeset
4 typedef typename MetaFun<Value>::type type;
anatofuz
parents:
diff changeset
5 };
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 template<class T>
anatofuz
parents:
diff changeset
8 struct add_pointer {
anatofuz
parents:
diff changeset
9 typedef T* type;
anatofuz
parents:
diff changeset
10 };
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 template<class T>
anatofuz
parents:
diff changeset
13 struct add_reference {
anatofuz
parents:
diff changeset
14 typedef T& type;
anatofuz
parents:
diff changeset
15 };
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 int i;
anatofuz
parents:
diff changeset
18 apply<add_pointer, int>::type ip = &i;
anatofuz
parents:
diff changeset
19 apply<add_reference, int>::type ir = i;
anatofuz
parents:
diff changeset
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'}}
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 // Template template parameters
anatofuz
parents:
diff changeset
23 template<int> struct B; // expected-note{{has a different type 'int'}}
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 template<typename T,
anatofuz
parents:
diff changeset
26 template<T Value> class X> // expected-error{{cannot have type 'float'}} \
anatofuz
parents:
diff changeset
27 // expected-note{{with type 'long'}}
anatofuz
parents:
diff changeset
28 struct X0 { };
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 X0<int, B> x0b1;
anatofuz
parents:
diff changeset
31 X0<float, B> x0b2; // expected-note{{while substituting}}
anatofuz
parents:
diff changeset
32 X0<long, B> x0b3; // expected-error{{template template argument has different template parameters}}
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 template<template<int V> class TT> // expected-note{{parameter with type 'int'}}
anatofuz
parents:
diff changeset
35 struct X1 { };
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 template<typename T, template<T V> class TT>
anatofuz
parents:
diff changeset
38 struct X2 {
anatofuz
parents:
diff changeset
39 X1<TT> x1; // expected-error{{has different template parameters}}
anatofuz
parents:
diff changeset
40 };
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 template<int V> struct X3i { };
anatofuz
parents:
diff changeset
43 template<long V> struct X3l { }; // expected-note{{different type 'long'}}
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 X2<int, X3i> x2okay;
anatofuz
parents:
diff changeset
46 X2<long, X3l> x2bad; // expected-note{{instantiation}}
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 template <typename T, template <T, T> class TT, class R = TT<1, 2> >
anatofuz
parents:
diff changeset
49 struct Comp {
anatofuz
parents:
diff changeset
50 typedef R r1;
anatofuz
parents:
diff changeset
51 template <T x, T y> struct gt {
anatofuz
parents:
diff changeset
52 static const bool result = x > y;
anatofuz
parents:
diff changeset
53 };
anatofuz
parents:
diff changeset
54 typedef gt<2, 1> r2;
anatofuz
parents:
diff changeset
55 };
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 template <int x, int y> struct lt {
anatofuz
parents:
diff changeset
58 static const bool result = x < y;
anatofuz
parents:
diff changeset
59 };
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 Comp<int, lt> c0;
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 namespace PR8629 {
anatofuz
parents:
diff changeset
64 template<template<int> class TT> struct X0
anatofuz
parents:
diff changeset
65 {
anatofuz
parents:
diff changeset
66 static void apply();
anatofuz
parents:
diff changeset
67 };
anatofuz
parents:
diff changeset
68 template<int> struct Type { };
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 template<class T> struct X1
anatofuz
parents:
diff changeset
71 {
anatofuz
parents:
diff changeset
72 template<class U> struct Inner;
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 template<class U> void g()
anatofuz
parents:
diff changeset
75 {
anatofuz
parents:
diff changeset
76 typedef Inner<U> Init;
anatofuz
parents:
diff changeset
77 X0<Init::template VeryInner>::apply();
anatofuz
parents:
diff changeset
78 }
anatofuz
parents:
diff changeset
79 template<int N> void f ()
anatofuz
parents:
diff changeset
80 {
anatofuz
parents:
diff changeset
81 g<Type<N> >();
anatofuz
parents:
diff changeset
82 }
anatofuz
parents:
diff changeset
83 };
anatofuz
parents:
diff changeset
84 template<class T> template<class U> struct X1<T>::Inner
anatofuz
parents:
diff changeset
85 {
anatofuz
parents:
diff changeset
86 template<int> struct VeryInner {
anatofuz
parents:
diff changeset
87 };
anatofuz
parents:
diff changeset
88 };
anatofuz
parents:
diff changeset
89 struct X1Container
anatofuz
parents:
diff changeset
90 {
anatofuz
parents:
diff changeset
91 X1Container()
anatofuz
parents:
diff changeset
92 {
anatofuz
parents:
diff changeset
93 simplex_.f<0>();
anatofuz
parents:
diff changeset
94 }
anatofuz
parents:
diff changeset
95 X1<double> simplex_;
anatofuz
parents:
diff changeset
96 };
anatofuz
parents:
diff changeset
97 }