236
|
1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx98-14 %s
|
|
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 -std=c++17 %s
|
150
|
3
|
|
4 template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}}
|
|
5
|
|
6 template<template<typename T, int I> class X> struct B; // expected-note{{previous template template parameter is here}}
|
|
7
|
|
8 template<template<int I> class X> struct C; // expected-note 2{{previous non-type template parameter with type 'int' is here}}
|
|
9
|
|
10 template<class> struct X; // expected-note{{too few template parameters in template template argument}}
|
|
11 template<int N> struct Y; // expected-note{{template parameter has a different kind in template argument}}
|
|
12 template<long N> struct Ylong; // expected-note{{template non-type parameter has a different type 'long' in template argument}}
|
|
13 template<const int &N> struct Yref; // expected-note{{template non-type parameter has a different type 'const int &' in template argument}}
|
|
14
|
|
15 namespace N {
|
|
16 template<class> struct Z;
|
|
17 }
|
|
18 template<class, class> struct TooMany; // expected-note{{too many template parameters in template template argument}}
|
|
19
|
|
20
|
236
|
21 A<X> *a1;
|
150
|
22 A<N::Z> *a2;
|
|
23 A< ::N::Z> *a3;
|
|
24
|
|
25 A<Y> *a4; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
|
26 A<TooMany> *a5; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
|
27 B<X> *a6; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
|
28 C<Y> *a7;
|
|
29 C<Ylong> *a8; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
|
30 C<Yref> *a9; // expected-error{{template template argument has different template parameters than its corresponding template template parameter}}
|
|
31
|
|
32 template<typename T> void f(int);
|
|
33
|
|
34 A<f> *a9; // expected-error{{must be a class template}}
|
|
35
|
|
36 // Evil digraph '<:' is parsed as '[', expect error.
|
|
37 A<::N::Z> *a10;
|
|
38 #if __cplusplus <= 199711L
|
|
39 // expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
|
|
40 #endif
|
|
41
|
|
42 // Do not do a digraph correction here.
|
|
43 A<: :N::Z> *a11; // expected-error{{expected expression}} \
|
236
|
44 precxx17-error{{a type specifier is required for all declarations}} \
|
|
45 cxx17-error{{expected unqualified-id}}
|
150
|
46
|
|
47 // PR7807
|
|
48 namespace N {
|
236
|
49 template <typename, typename = int>
|
150
|
50 struct X
|
|
51 { };
|
|
52
|
236
|
53 template <typename ,int>
|
150
|
54 struct Y
|
|
55 { X<int> const_ref(); };
|
|
56
|
236
|
57 template <template<typename,int> class TT, typename T, int N>
|
150
|
58 int operator<<(int, TT<T, N> a) { // expected-note{{candidate template ignored}}
|
|
59 0 << a.const_ref(); // expected-error{{invalid operands to binary expression ('int' and 'X<int>')}}
|
|
60 }
|
|
61
|
236
|
62 void f0( Y<int,1> y){ 1 << y; } // expected-note{{in instantiation of function template specialization 'N::operator<<<N::Y, int, 1>' requested here}}
|
150
|
63 }
|
|
64
|
|
65 // PR12179
|
|
66 template <typename Primitive, template <Primitive...> class F>
|
|
67 #if __cplusplus <= 199711L
|
|
68 // expected-warning@-2 {{variadic templates are a C++11 extension}}
|
|
69 #endif
|
|
70
|
|
71 struct unbox_args {
|
|
72 typedef typename Primitive::template call<F> x;
|
|
73 };
|
|
74
|
|
75 template <template <typename> class... Templates>
|
|
76 #if __cplusplus <= 199711L
|
|
77 // expected-warning@-2 {{variadic templates are a C++11 extension}}
|
|
78 #endif
|
|
79
|
|
80 struct template_tuple {
|
|
81 #if __cplusplus >= 201103L
|
|
82 static constexpr int N = sizeof...(Templates);
|
|
83 #endif
|
|
84 };
|
|
85 template <typename T>
|
|
86 struct identity {};
|
|
87 template <template <typename> class... Templates>
|
|
88 #if __cplusplus <= 199711L
|
|
89 // expected-warning@-2 {{variadic templates are a C++11 extension}}
|
|
90 #endif
|
|
91
|
|
92 template_tuple<Templates...> f7() {}
|
|
93
|
|
94 #if __cplusplus >= 201103L
|
|
95 struct S : public template_tuple<identity, identity> {
|
|
96 static_assert(N == 2, "Number of template arguments incorrect");
|
|
97 };
|
|
98 #endif
|
|
99
|
|
100 void foo() {
|
|
101 f7<identity>();
|
|
102 }
|
|
103
|
|
104 namespace CheckDependentNonTypeParamTypes {
|
|
105 template<template<typename T, typename U, T v> class X> struct A {
|
|
106 void f() {
|
236
|
107 X<int, void*, 3> x; // precxx17-error {{does not refer to any declaration}} \
|
|
108 cxx17-error {{value of type 'int' is not implicitly convertible to 'void *'}}
|
150
|
109 }
|
|
110 void g() {
|
|
111 X<int, long, 3> x;
|
|
112 }
|
|
113 void h() {
|
|
114 // FIXME: If we accept A<B> at all, it's not obvious what should happen
|
|
115 // here. While parsing the template, we form
|
|
116 // X<unsigned char, int, (unsigned char)1234>
|
|
117 // but in the final instantiation do we get
|
|
118 // B<unsigned char, int, (int)1234>
|
|
119 // or
|
|
120 // B<unsigned char, int, (int)(unsigned char)1234>
|
|
121 // ?
|
|
122 X<unsigned char, int, 1234> x;
|
|
123 int check[x.value == 1234 ? 1 : -1];
|
|
124 }
|
|
125 };
|
|
126
|
236
|
127 template<typename T, typename U, U v> struct B { // precxx17-note {{parameter}}
|
150
|
128 static const U value = v;
|
|
129 };
|
|
130
|
|
131 // FIXME: This should probably be rejected, but the rules are at best unclear.
|
|
132 A<B> ab;
|
|
133
|
|
134 void use() {
|
|
135 ab.f(); // expected-note {{instantiation of}}
|
|
136 ab.g();
|
|
137 ab.h();
|
|
138 }
|
|
139 }
|
|
140
|
|
141 namespace PR32185 {
|
|
142 template<template<typename T, T> class U> struct A {};
|
|
143 template<template<typename T, T> class U> struct B : A<U> {};
|
|
144 }
|
|
145
|
|
146 namespace PR10147 {
|
|
147 template<typename T> struct A {};
|
|
148 template<typename T = int> struct A;
|
|
149 template<template<typename...> class A> void f(A<int>*) { A<> a; } // expected-warning 0-1{{extension}}
|
|
150 void g() { f((A<>*)0); }
|
|
151 }
|