xref: /llvm-project/clang/test/CXX/drs/cwg22xx.cpp (revision 14ba3f9d07ea1664497c5d117120fb243ca221aa)
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
8 
9 
10 namespace cwg2211 { // cwg2211: 8
11 #if __cplusplus >= 201103L
12 void f() {
13   int a;
14   auto f = [a](int a) { (void)a; };
15   // since-cxx11-error@-1 {{a lambda parameter cannot shadow an explicitly captured entity}}
16   //   since-cxx11-note@-2 {{variable 'a' is explicitly captured here}}
17   auto g = [=](int a) { (void)a; };
18 }
19 #endif
20 } // namespace cwg2211
21 
22 namespace cwg2213 { // cwg2213: 2.7
23 template <typename T, typename U>
24 struct A;
25 
26 template <typename U>
27 struct A<int, U>;
28 } // namespace cwg2213
29 
30 namespace cwg2229 { // cwg2229: 7
31 struct AnonBitfieldQualifiers {
32   const unsigned : 1;
33   // expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
34   volatile unsigned : 1;
35   // expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
36   const volatile unsigned : 1;
37   // expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
38 
39   unsigned : 1;
40   const unsigned i1 : 1;
41   volatile unsigned i2 : 1;
42   const volatile unsigned i3 : 1;
43 };
44 } // namespace cwg2229
45 
46 namespace cwg2233 { // cwg2233: 11
47 #if __cplusplus >= 201103L
48 template <typename... T>
49 void f(int i = 0, T... args) {}
50 
51 template <typename... T>
52 void g(int i = 0, T... args, T... args2) {}
53 
54 template <typename... T>
55 void h(int i = 0, T... args, int j = 1) {}
56 
57 template <typename... T, typename... U>
58 void i(int i = 0, T... args, int j = 1, U... args2) {}
59 
60 template <class... Ts>
61 void j(int i = 0, Ts... ts) {}
62 
63 template <>
64 void j<int>(int i, int j) {}
65 
66 template
67 void j(int, int, int);
68 
69 extern template
70 void j(int, int, int, int);
71 
72 // PR23029
73 // Ensure instantiating the templates works.
74 void use() {
75   f();
76   f(0, 1);
77   f<int>(1, 2);
78   g<int>(1, 2, 3);
79   h(0, 1);
80   i();
81   i(3);
82   i<int>(3, 2);
83   i<int>(3, 2, 1);
84   i<int, int>(1, 2, 3, 4, 5);
85   j();
86   j(1);
87   j(1, 2);
88   j<int>(1, 2);
89 }
90 
91 namespace MultilevelSpecialization {
92   template<typename ...T> struct A {
93     template <T... V> void f(int i = 0, int (&... arr)[V]);
94   };
95   template<> template<>
96     void A<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
97 
98   // FIXME: I believe this example is valid, at least up to the first explicit
99   // specialization, but Clang can't cope with explicit specializations that
100   // expand packs into a sequence of parameters. If we ever start accepting
101   // that, we'll need to decide whether it's OK for arr1a to be missing its
102   // default argument -- how far back do we look when determining whether a
103   // parameter was expanded from a pack?
104   //   -- zygoloid 2020-06-02
105   template<typename ...T> struct B { // #cwg2233-B
106     template <T... V> void f(int i = 0, int (&... arr)[V]);
107   };
108   template<> template<int a, int b>
109     void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {}
110     // since-cxx11-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg2233::MultilevelSpecialization::B<int, int>'}}
111     //   since-cxx11-note@#cwg2233-B {{defined here}}
112   template<> template<>
113     void B<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
114 }
115 
116 namespace CheckAfterMerging1 {
117   template <typename... T> void f() {
118     void g(int, int = 0);
119     void g(int = 0, T...);
120     g();
121   }
122   void h() { f<int>(); }
123 }
124 
125 namespace CheckAfterMerging2 {
126   template <typename... T> void f() {
127     void g(int = 0, T...);
128     void g(int, int = 0);
129     g();
130   }
131   void h() { f<int>(); }
132 }
133 #endif
134 } // namespace cwg2233
135 
136 namespace cwg2267 { // cwg2267: no
137 #if __cplusplus >= 201103L
138 struct A {} a;
139 struct B { explicit B(const A&); }; // #cwg2267-struct-B
140 
141 struct D { D(); };
142 struct C { explicit operator D(); } c;
143 
144 B b1(a);
145 const B &b2{a}; // FIXME ill-formed
146 const B &b3(a);
147 // since-cxx11-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
148 //   since-cxx11-note@#cwg2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}}
149 //   since-cxx11-note@#cwg2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}}
150 //   since-cxx11-note@#cwg2267-struct-B {{explicit constructor is not a candidate}}
151 
152 D d1(c);
153 const D &d2{c}; // FIXME ill-formed
154 const D &d3(c); // FIXME ill-formed
155 #endif
156 } // namespace cwg2267
157 
158 namespace cwg2273 { // cwg2273: 3.3
159 #if __cplusplus >= 201103L
160 struct A {
161   A(int = 0) = delete; // #cwg2273-A
162 };
163 
164 struct B : A { // #cwg2273-B
165   using A::A;
166 };
167 
168 B b;
169 // since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'B'}}
170 //   since-cxx11-note@#cwg2273-B {{default constructor of 'B' is implicitly deleted because base class 'A' has a deleted default constructor}}
171 //   since-cxx11-note@#cwg2273-A {{'A' has been explicitly marked deleted here}}
172 #endif
173 } // namespace cwg2273
174 
175 namespace cwg2277 { // cwg2277: partial
176 #if __cplusplus >= 201103L
177 struct A {
178   A(int, int = 0);
179   void f(int, int = 0); // #cwg2277-A-f
180 };
181 struct B : A {
182   B(int);
183   using A::A;
184 
185   void f(int); // #cwg2277-B-f
186   using A::f;
187 };
188 
189 void g() {
190   B b{0};
191   b.f(0); // FIXME: this is well-formed for the same reason as initialization of 'b' above
192   // since-cxx11-error@-1 {{call to member function 'f' is ambiguous}}
193   //   since-cxx11-note@#cwg2277-A-f {{candidate function}}
194   //   since-cxx11-note@#cwg2277-B-f {{candidate function}}
195 }
196 #endif
197 } // namespace cwg2277
198 
199 namespace cwg2292 { // cwg2292: 9
200 #if __cplusplus >= 201103L
201   template<typename T> using id = T;
202   void test(int *p) {
203     p->template id<int>::~id<int>();
204   }
205 #endif
206 } // namespace cwg2292
207