annotate clang/test/SemaTemplate/temp_arg_template.cpp @ 236:c4bab56944e8 llvm-original

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