Debian Codegraph @

clang/test/CXX/drs/cwg22xx.cpp

raw
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 #if __cplusplus >= 201103L
11 namespace cwg2211 { // cwg2211: 8
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 }
20 #endif
21
22 namespace cwg2213 { // cwg2213: yes
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 }
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 {
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 template<> template<>
112 void B<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
113 }
114
115 namespace CheckAfterMerging1 {
116 template <typename... T> void f() {
117 void g(int, int = 0);
118 void g(int = 0, T...);
119 g();
120 }
121 void h() { f<int>(); }
122 }
123
124 namespace CheckAfterMerging2 {
125 template <typename... T> void f() {
126 void g(int = 0, T...);
127 void g(int, int = 0);
128 g();
129 }
130 void h() { f<int>(); }
131 }
132 #endif
133 } // namespace cwg2233
134
135 namespace cwg2267 { // cwg2267: no
136 #if __cplusplus >= 201103L
137 struct A {} a;
138 struct B { explicit B(const A&); }; // #cwg2267-struct-B
139
140 struct D { D(); };
141 struct C { explicit operator D(); } c;
142
143 B b1(a);
144 const B &b2{a}; // FIXME ill-formed
145 const B &b3(a);
146 // since-cxx11-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
147 // 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}}
148 // 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}}
149 // since-cxx11-note@#cwg2267-struct-B {{explicit constructor is not a candidate}}
150
151 D d1(c);
152 const D &d2{c}; // FIXME ill-formed
153 const D &d3(c); // FIXME ill-formed
154 #endif
155 }
156
157 namespace cwg2273 { // cwg2273: 3.3
158 #if __cplusplus >= 201103L
159 struct A {
160 A(int = 0) = delete; // #cwg2273-A
161 };
162
163 struct B : A { // #cwg2273-B
164 using A::A;
165 };
166
167 B b;
168 // since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'B'}}
169 // since-cxx11-note@#cwg2273-B {{default constructor of 'B' is implicitly deleted because base class 'A' has a deleted default constructor}}
170 // since-cxx11-note@#cwg2273-A {{'A' has been explicitly marked deleted here}}
171 #endif
172 }
173
174 namespace cwg2277 { // cwg2277: partial
175 #if __cplusplus >= 201103L
176 struct A {
177 A(int, int = 0);
178 void f(int, int = 0); // #cwg2277-A-f
179 };
180 struct B : A {
181 B(int);
182 using A::A;
183
184 void f(int); // #cwg2277-B-f
185 using A::f;
186 };
187
188 void g() {
189 B b{0};
190 b.f(0); // FIXME: this is well-formed for the same reason as initialization of 'b' above
191 // since-cxx11-error@-1 {{call to member function 'f' is ambiguous}}
192 // since-cxx11-note@#cwg2277-A-f {{candidate function}}
193 // since-cxx11-note@#cwg2277-B-f {{candidate function}}
194 }
195 #endif
196 }
197
198 namespace cwg2292 { // cwg2292: 9
199 #if __cplusplus >= 201103L
200 template<typename T> using id = T;
201 void test(int *p) {
202 p->template id<int>::~id<int>();
203 }
204 #endif
205 }