1 | // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
2 | // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
3 | // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
4 | // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors |
5 | |
6 | namespace dr300 { // dr300: yes |
7 | template<typename R, typename A> void f(R (&)(A)) {} |
8 | int g(int); |
9 | void h() { f(g); } |
10 | } |
11 | |
12 | namespace dr301 { // dr301: yes |
13 | // see also dr38 |
14 | struct S; |
15 | template<typename T> void operator+(T, T); |
16 | void operator-(S, S); |
17 | |
18 | void f() { |
19 | bool a = (void(*)(S, S))operator+<S> < |
20 | (void(*)(S, S))operator+<S>; |
21 | bool b = (void(*)(S, S))operator- < |
22 | (void(*)(S, S))operator-; |
23 | bool c = (void(*)(S, S))operator+ < |
24 | (void(*)(S, S))operator-; // expected-error {{expected '>'}} |
25 | } |
26 | |
27 | template<typename T> void f() { |
28 | typename T::template operator+<int> a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}} |
29 | // FIXME: This shouldn't say (null). |
30 | class T::template operator+<int> b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}} |
31 | enum T::template operator+<int> c; // expected-error {{expected identifier}} expected-error {{does not declare anything}} |
32 | enum T::template operator+<int>::E d; // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} expected-error {{forward reference}} |
33 | enum T::template X<int>::E e; |
34 | T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} |
35 | T::template operator+<int>(0); // ok |
36 | } |
37 | |
38 | template<typename T> class operator&<T*> {}; // expected-error +{{}} |
39 | template<typename T> class T::operator& {}; // expected-error +{{}} |
40 | template<typename T> class S::operator&<T*> {}; // expected-error +{{}} |
41 | } |
42 | |
43 | namespace dr302 { // dr302: yes |
44 | struct A { A(); ~A(); }; |
45 | #if __cplusplus < 201103L |
46 | struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}} |
47 | const int n; // expected-note {{declared here}} |
48 | A a; |
49 | } b = B(); // expected-note {{first required here}} |
50 | // Trivial default constructor C::C() is not called here. |
51 | struct C { |
52 | const int n; |
53 | } c = C(); |
54 | #else |
55 | struct B { |
56 | const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}} |
57 | A a; |
58 | } b = B(); // expected-error {{call to implicitly-deleted default constructor}} |
59 | // C::C() is called here, because even though it's trivial, it's deleted. |
60 | struct C { |
61 | const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}} |
62 | } c = C(); // expected-error {{call to implicitly-deleted default constructor}} |
63 | struct D { |
64 | const int n = 0; |
65 | } d = D(); |
66 | #endif |
67 | } |
68 | |
69 | // dr303: na |
70 | |
71 | namespace dr304 { // dr304: yes |
72 | typedef int &a; |
73 | int n = a(); // expected-error {{requires an initializer}} |
74 | |
75 | struct S { int &b; }; |
76 | int m = S().b; |
77 | #if __cplusplus < 201103L |
78 | // expected-error@-3 {{requires an initializer}} |
79 | // expected-note@-3 {{in value-initialization}} |
80 | #else |
81 | // expected-error@-5 {{deleted}} |
82 | // expected-note@-7 {{reference}} |
83 | #endif |
84 | } |
85 | |
86 | namespace dr305 { // dr305: no |
87 | struct A { |
88 | typedef A C; |
89 | }; |
90 | void f(A *a) { |
91 | struct A {}; |
92 | a->~A(); |
93 | a->~C(); |
94 | } |
95 | typedef A B; |
96 | void g(B *b) { |
97 | b->~B(); |
98 | b->~C(); |
99 | } |
100 | void h(B *b) { |
101 | struct B {}; // expected-note {{declared here}} |
102 | b->~B(); // expected-error {{does not match}} |
103 | } |
104 | |
105 | template<typename T> struct X {}; |
106 | void i(X<int>* x) { |
107 | struct X {}; |
108 | x->~X<int>(); |
109 | x->~X(); |
110 | x->~X<char>(); // expected-error {{no member named}} |
111 | } |
112 | |
113 | #if __cplusplus >= 201103L |
114 | struct Y { |
115 | template<typename T> using T1 = Y; |
116 | }; |
117 | template<typename T> using T2 = Y; |
118 | void j(Y *y) { |
119 | y->~T1<int>(); |
120 | y->~T2<int>(); |
121 | } |
122 | struct Z { |
123 | template<typename T> using T2 = T; |
124 | }; |
125 | void k(Z *z) { |
126 | z->~T1<int>(); // expected-error {{no member named 'T1' in 'dr305::Z'}} expected-error +{{}} |
127 | z->~T2<int>(); // expected-error {{no member named '~int'}} |
128 | z->~T2<Z>(); |
129 | } |
130 | |
131 | // FIXME: This is valid. |
132 | namespace Q { |
133 | template<typename A> struct R {}; |
134 | } |
135 | template<typename A> using R = Q::R<int>; |
136 | void qr(Q::R<int> x) { x.~R<char>(); } // expected-error {{no member named}} |
137 | #endif |
138 | } |
139 | |
140 | namespace dr306 { // dr306: no |
141 | // FIXME: dup 39 |
142 | // FIXME: This should be accepted. |
143 | struct A { struct B {}; }; // expected-note 2{{member}} |
144 | struct C { typedef A::B B; }; // expected-note {{member}} |
145 | struct D : A, A::B, C {}; |
146 | D::B b; // expected-error {{found in multiple base classes of different types}} |
147 | } |
148 | |
149 | // dr307: na |
150 | |
151 | namespace dr308 { // dr308: yes |
152 | // This is mostly an ABI library issue. |
153 | struct A {}; |
154 | struct B : A {}; |
155 | struct C : A {}; |
156 | struct D : B, C {}; |
157 | void f() { |
158 | try { |
159 | throw D(); |
160 | } catch (const A&) { // expected-note {{for type 'const dr308::A &'}} |
161 | // unreachable |
162 | } catch (const B&) { // expected-warning {{exception of type 'const dr308::B &' will be caught by earlier handler}} |
163 | // get here instead |
164 | } |
165 | } |
166 | } |
167 | |
168 | // dr309: dup 485 |
169 | |
170 | namespace dr311 { // dr311: yes |
171 | namespace X { namespace Y {} } |
172 | namespace X::Y {} |
173 | #if __cplusplus <= 201402L |
174 | // expected-error@-2 {{define each namespace separately}} |
175 | #endif |
176 | namespace X { |
177 | namespace X::Y {} |
178 | #if __cplusplus <= 201402L |
179 | // expected-error@-2 {{define each namespace separately}} |
180 | #endif |
181 | } |
182 | // FIXME: The diagnostics here are not very good. |
183 | namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}} |
184 | } |
185 | |
186 | // dr312: dup 616 |
187 | |
188 | namespace dr313 { // dr313: dup 299 c++11 |
189 | struct A { operator int() const; }; |
190 | int *p = new int[A()]; |
191 | #if __cplusplus < 201103L |
192 | // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}} |
193 | #endif |
194 | } |
195 | |
196 | namespace dr314 { // FIXME 314: dup 1710 |
197 | template<typename T> struct A { |
198 | template<typename U> struct B {}; |
199 | }; |
200 | template<typename T> struct C : public A<T>::template B<T> { |
201 | C() : A<T>::template B<T>() {} |
202 | }; |
203 | } |
204 | |
205 | // dr315: na |
206 | // dr316: sup 1004 |
207 | |
208 | namespace dr317 { // dr317: 3.5 |
209 | void f() {} // expected-note {{previous}} |
210 | inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}} |
211 | |
212 | int g(); |
213 | int n = g(); |
214 | inline int g() { return 0; } |
215 | |
216 | int h(); |
217 | int m = h(); |
218 | int h() { return 0; } // expected-note {{previous}} |
219 | inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}} |
220 | } |
221 | |
222 | namespace dr318 { // dr318: sup 1310 |
223 | struct A {}; |
224 | struct A::A a; |
225 | } |
226 | |
227 | namespace dr319 { // dr319: no |
228 | // FIXME: dup dr389 |
229 | // FIXME: We don't have a diagnostic for a name with linkage |
230 | // having a type without linkage. |
231 | typedef struct { |
232 | int i; |
233 | } *ps; |
234 | extern "C" void f(ps); |
235 | void g(ps); // FIXME: ill-formed, type 'ps' has no linkage |
236 | |
237 | static enum { e } a1; |
238 | enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage |
239 | |
240 | enum { n1 = 1u }; |
241 | typedef int (*pa)[n1]; |
242 | pa parr; // ok, type has linkage despite using 'n1' |
243 | |
244 | template<typename> struct X {}; |
245 | |
246 | void f() { |
247 | struct A { int n; }; |
248 | extern A a; // FIXME: ill-formed |
249 | X<A> xa; |
250 | |
251 | typedef A B; |
252 | extern B b; // FIXME: ill-formed |
253 | X<B> xb; |
254 | |
255 | const int n = 1; |
256 | typedef int (*C)[n]; |
257 | extern C c; // ok |
258 | X<C> xc; |
259 | } |
260 | #if __cplusplus < 201103L |
261 | // expected-error@-12 {{uses local type 'A'}} |
262 | // expected-error@-9 {{uses local type 'A'}} |
263 | #endif |
264 | } |
265 | |
266 | namespace dr320 { // dr320: yes |
267 | #if __cplusplus >= 201103L |
268 | struct X { |
269 | constexpr X() {} |
270 | constexpr X(const X &x) : copies(x.copies + 1) {} |
271 | unsigned copies = 0; |
272 | }; |
273 | constexpr X f(X x) { return x; } |
274 | constexpr unsigned g(X x) { return x.copies; } |
275 | static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value"); |
276 | #endif |
277 | } |
278 | |
279 | namespace dr321 { // dr321: dup 557 |
280 | namespace N { |
281 | template<int> struct A { |
282 | template<int> struct B; |
283 | }; |
284 | template<> template<> struct A<0>::B<0>; |
285 | void f(A<0>::B<0>); |
286 | } |
287 | template<> template<> struct N::A<0>::B<0> {}; |
288 | |
289 | template<typename T> void g(T t) { f(t); } |
290 | template void g(N::A<0>::B<0>); |
291 | |
292 | namespace N { |
293 | template<typename> struct I { friend bool operator==(const I&, const I&); }; |
294 | } |
295 | N::I<int> i, j; |
296 | bool x = i == j; |
297 | } |
298 | |
299 | namespace dr322 { // dr322: yes |
300 | struct A { |
301 | template<typename T> operator T&(); |
302 | } a; |
303 | int &r = static_cast<int&>(a); |
304 | int &s = a; |
305 | } |
306 | |
307 | // dr323: no |
308 | |
309 | namespace dr324 { // dr324: yes |
310 | struct S { int n : 1; } s; // expected-note 3{{bit-field is declared here}} |
311 | int &a = s.n; // expected-error {{non-const reference cannot bind to bit-field}} |
312 | int *b = &s.n; // expected-error {{address of bit-field}} |
313 | int &c = (s.n = 0); // expected-error {{non-const reference cannot bind to bit-field}} |
314 | int *d = &(s.n = 0); // expected-error {{address of bit-field}} |
315 | int &e = true ? s.n : s.n; // expected-error {{non-const reference cannot bind to bit-field}} |
316 | int *f = &(true ? s.n : s.n); // expected-error {{address of bit-field}} |
317 | int &g = (void(), s.n); // expected-error {{non-const reference cannot bind to bit-field}} |
318 | int *h = &(void(), s.n); // expected-error {{address of bit-field}} |
319 | int *i = &++s.n; // expected-error {{address of bit-field}} |
320 | } |
321 | |
322 | namespace dr326 { // dr326: yes |
323 | struct S {}; |
324 | int test[__is_trivially_constructible(S, const S&) ? 1 : -1]; |
325 | } |
326 | |
327 | namespace dr327 { // dr327: dup 538 |
328 | struct A; |
329 | class A {}; |
330 | |
331 | class B; |
332 | struct B {}; |
333 | } |
334 | |
335 | namespace dr328 { // dr328: yes |
336 | struct A; // expected-note 3{{forward declaration}} |
337 | struct B { A a; }; // expected-error {{incomplete}} |
338 | template<typename> struct C { A a; }; // expected-error {{incomplete}} |
339 | A *p = new A[0]; // expected-error {{incomplete}} |
340 | } |
341 | |
342 | namespace dr329 { // dr329: 3.5 |
343 | struct B {}; |
344 | template<typename T> struct A : B { |
345 | friend void f(A a) { g(a); } |
346 | friend void h(A a) { g(a); } // expected-error {{undeclared}} |
347 | friend void i(B b) {} // expected-error {{redefinition}} expected-note {{previous}} |
348 | }; |
349 | A<int> a; |
350 | A<char> b; // expected-note {{instantiation}} |
351 | |
352 | void test() { |
353 | h(a); // expected-note {{instantiation}} |
354 | } |
355 | } |
356 | |
357 | namespace dr330 { // dr330: 7 |
358 | // Conversions between P and Q will be allowed by P0388. |
359 | typedef int *(*P)[3]; |
360 | typedef const int *const (*Q)[3]; |
361 | typedef const int *Qinner[3]; |
362 | typedef Qinner const *Q2; // same as Q, but 'const' written outside the array type |
363 | typedef const int *const (*R)[4]; |
364 | typedef const int *const (*S)[]; |
365 | typedef const int *(*T)[]; |
366 | void f(P p, Q q, Q2 q2, R r, S s, T t) { |
367 | q = p; // ok |
368 | q2 = p; // ok |
369 | r = p; // expected-error {{incompatible}} |
370 | s = p; // expected-error {{incompatible}} (for now) |
371 | t = p; // expected-error {{incompatible}} |
372 | s = q; // expected-error {{incompatible}} |
373 | s = q2; // expected-error {{incompatible}} |
374 | s = t; // ok, adding const |
375 | t = s; // expected-error {{incompatible}} |
376 | (void) const_cast<P>(q); |
377 | (void) const_cast<P>(q2); |
378 | (void) const_cast<Q>(p); |
379 | (void) const_cast<Q2>(p); |
380 | (void) const_cast<S>(p); // expected-error {{not allowed}} (for now) |
381 | (void) const_cast<P>(s); // expected-error {{not allowed}} (for now) |
382 | (void) const_cast<S>(q); // expected-error {{not allowed}} |
383 | (void) const_cast<S>(q2); // expected-error {{not allowed}} |
384 | (void) const_cast<Q>(s); // expected-error {{not allowed}} |
385 | (void) const_cast<Q2>(s); // expected-error {{not allowed}} |
386 | (void) const_cast<T>(s); |
387 | (void) const_cast<S>(t); |
388 | (void) const_cast<T>(q); // expected-error {{not allowed}} |
389 | (void) const_cast<Q>(t); // expected-error {{not allowed}} |
390 | |
391 | (void) reinterpret_cast<P>(q); // expected-error {{casts away qualifiers}} |
392 | (void) reinterpret_cast<P>(q2); // expected-error {{casts away qualifiers}} |
393 | (void) reinterpret_cast<Q>(p); |
394 | (void) reinterpret_cast<Q2>(p); |
395 | (void) reinterpret_cast<S>(p); |
396 | (void) reinterpret_cast<P>(s); // expected-error {{casts away qualifiers}} |
397 | (void) reinterpret_cast<S>(q); |
398 | (void) reinterpret_cast<S>(q2); |
399 | (void) reinterpret_cast<Q>(s); |
400 | (void) reinterpret_cast<Q2>(s); |
401 | (void) reinterpret_cast<T>(s); // expected-error {{casts away qualifiers}} |
402 | (void) reinterpret_cast<S>(t); |
403 | (void) reinterpret_cast<T>(q); // expected-error {{casts away qualifiers}} |
404 | (void) reinterpret_cast<Q>(t); |
405 | } |
406 | |
407 | namespace swift_17882 { |
408 | typedef const char P[72]; |
409 | typedef int *Q; |
410 | void f(P &pr, P *pp) { |
411 | (void) reinterpret_cast<const Q&>(pr); |
412 | (void) reinterpret_cast<const Q*>(pp); |
413 | } |
414 | |
415 | struct X {}; |
416 | typedef const volatile int A[1][2][3]; |
417 | typedef int *const X::*volatile *B1; |
418 | typedef int *const X::* *B2; |
419 | typedef int *X::* volatile *B3; |
420 | typedef volatile int *(*const B4)[4]; |
421 | void f(A *a) { |
422 | (void) reinterpret_cast<B1*>(a); |
423 | (void) reinterpret_cast<B2*>(a); // expected-error {{casts away qualifiers}} |
424 | (void) reinterpret_cast<B3*>(a); // expected-error {{casts away qualifiers}} |
425 | (void) reinterpret_cast<B4*>(a); |
426 | } |
427 | } |
428 | } |
429 | |
430 | namespace dr331 { // dr331: yes |
431 | struct A { |
432 | A(volatile A&); // expected-note {{candidate}} |
433 | } const a, b(a); // expected-error {{no matching constructor}} |
434 | } |
435 | |
436 | namespace dr332 { // dr332: dup 577 |
437 | void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}} |
438 | void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}} |
439 | void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}} |
440 | } |
441 | |
442 | namespace dr333 { // dr333: yes |
443 | int n = 0; |
444 | int f(int(n)); |
445 | int g((int(n))); |
446 | int h = f(g); |
447 | } |
448 | |
449 | namespace dr334 { // dr334: yes |
450 | template<typename T> void f() { |
451 | T x; |
452 | f((x, 123)); |
453 | } |
454 | struct S { |
455 | friend S operator,(S, int); |
456 | friend void f(S); |
457 | }; |
458 | template void f<S>(); |
459 | } |
460 | |
461 | // dr335: no |
462 | |
463 | namespace dr336 { // dr336: yes |
464 | namespace Pre { |
465 | template<class T1> class A { |
466 | template<class T2> class B { |
467 | template<class T3> void mf1(T3); |
468 | void mf2(); |
469 | }; |
470 | }; |
471 | template<> template<class X> class A<int>::B {}; |
472 | template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} // expected-error {{does not match}} |
473 | template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}} |
474 | } |
475 | namespace Post { |
476 | template<class T1> class A { |
477 | template<class T2> class B { |
478 | template<class T3> void mf1(T3); |
479 | void mf2(); |
480 | }; |
481 | }; |
482 | template<> template<class X> class A<int>::B { |
483 | template<class T> void mf1(T); |
484 | }; |
485 | template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} |
486 | // FIXME: This diagnostic isn't very good. |
487 | template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}} |
488 | } |
489 | } |
490 | |
491 | namespace dr337 { // dr337: yes |
492 | template<typename T> void f(T (*)[1]); |
493 | template<typename T> int &f(...); |
494 | |
495 | struct A { virtual ~A() = 0; }; |
496 | int &r = f<A>(0); |
497 | |
498 | // FIXME: The language rules here are completely broken. We cannot determine |
499 | // whether an incomplete type is abstract. See DR1640, which will probably |
500 | // supersede this one and remove this rule. |
501 | struct B; |
502 | int &s = f<B>(0); // expected-error {{of type 'void'}} |
503 | struct B { virtual ~B() = 0; }; |
504 | } |
505 | |
506 | namespace dr339 { // dr339: yes |
507 | template <int I> struct A { static const int value = I; }; |
508 | |
509 | char xxx(int); |
510 | char (&xxx(float))[2]; |
511 | |
512 | template<class T> A<sizeof(xxx((T)0))> f(T) {} // expected-note {{candidate}} |
513 | |
514 | void test() { |
515 | A<1> a = f(0); |
516 | A<2> b = f(0.0f); |
517 | A<3> c = f("foo"); // expected-error {{no matching function}} |
518 | } |
519 | |
520 | |
521 | char f(int); |
522 | int f(...); |
523 | |
524 | template <class T> struct conv_int { |
525 | static const bool value = sizeof(f(T())) == 1; |
526 | }; |
527 | |
528 | template <class T> bool conv_int2(A<sizeof(f(T()))> p); |
529 | |
530 | template<typename T> A<sizeof(f(T()))> make_A(); |
531 | |
532 | int a[conv_int<char>::value ? 1 : -1]; |
533 | bool b = conv_int2<char>(A<1>()); |
534 | A<1> c = make_A<char>(); |
535 | } |
536 | |
537 | namespace dr340 { // dr340: yes |
538 | struct A { A(int); }; |
539 | struct B { B(A, A, int); }; |
540 | int x, y; |
541 | B b(A(x), A(y), 3); |
542 | } |
543 | |
544 | namespace dr341 { // dr341: sup 1708 |
545 | namespace A { |
546 | int n; |
547 | extern "C" int &dr341_a = n; // expected-note {{previous}} expected-note {{declared with C language linkage here}} |
548 | } |
549 | namespace B { |
550 | extern "C" int &dr341_a = dr341_a; // expected-error {{redefinition}} |
551 | } |
552 | extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}} |
553 | } |
554 | int dr341_a; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}} |
555 | int dr341_b; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}} |
556 | int dr341_c; // expected-note {{declared in global scope here}} |
557 | int dr341_d; // expected-note {{declared in global scope here}} |
558 | namespace dr341 { |
559 | extern "C" int dr341_c; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}} |
560 | extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}} |
561 | |
562 | namespace A { extern "C" int dr341_e; } // expected-note {{previous}} |
563 | namespace B { extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}} |
564 | } |
565 | |
566 | // dr342: na |
567 | |
568 | namespace dr343 { // FIXME 343: no |
569 | // FIXME: dup 1710 |
570 | template<typename T> struct A { |
571 | template<typename U> struct B {}; |
572 | }; |
573 | // FIXME: In these contexts, the 'template' keyword is optional. |
574 | template<typename T> struct C : public A<T>::B<T> { // expected-error {{use 'template'}} |
575 | C() : A<T>::B<T>() {} // expected-error {{use 'template'}} |
576 | }; |
577 | } |
578 | |
579 | namespace dr344 { // dr344: dup 1435 |
580 | struct A { inline virtual ~A(); }; |
581 | struct B { friend A::~A(); }; |
582 | } |
583 | |
584 | namespace dr345 { // dr345: yes |
585 | struct A { |
586 | struct X {}; |
587 | int X; // expected-note {{here}} |
588 | }; |
589 | struct B { |
590 | struct X {}; |
591 | }; |
592 | template <class T> void f(T t) { typename T::X x; } // expected-error {{refers to non-type member 'X'}} |
593 | void f(A a, B b) { |
594 | f(b); |
595 | f(a); // expected-note {{instantiation}} |
596 | } |
597 | } |
598 | |
599 | // dr346: na |
600 | |
601 | namespace dr347 { // dr347: yes |
602 | struct base { |
603 | struct nested; |
604 | static int n; |
605 | static void f(); |
606 | void g(); |
607 | }; |
608 | |
609 | struct derived : base {}; |
610 | |
611 | struct derived::nested {}; // expected-error {{no struct named 'nested'}} |
612 | int derived::n; // expected-error {{no member named 'n'}} |
613 | void derived::f() {} // expected-error {{does not match any}} |
614 | void derived::g() {} // expected-error {{does not match any}} |
615 | } |
616 | |
617 | // dr348: na |
618 | |
619 | namespace dr349 { // dr349: no |
620 | struct A { |
621 | template <class T> operator T ***() { |
622 | int ***p = 0; |
623 | return p; // expected-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}} |
624 | } |
625 | }; |
626 | |
627 | // FIXME: This is valid. |
628 | A a; |
629 | const int *const *const *p1 = a; // expected-note {{in instantiation of}} |
630 | |
631 | struct B { |
632 | template <class T> operator T ***() { |
633 | const int ***p = 0; |
634 | return p; |
635 | } |
636 | }; |
637 | |
638 | // FIXME: This is invalid. |
639 | B b; |
640 | const int *const *const *p2 = b; |
641 | } |
642 | |
643 | // dr351: na |
644 | |
645 | namespace dr352 { // dr352: yes |
646 | namespace example1 { |
647 | namespace A { |
648 | enum E {}; |
649 | template<typename R, typename A> void foo(E, R (*)(A)); // expected-note 2{{couldn't infer template argument 'R'}} |
650 | } |
651 | |
652 | template<typename T> void arg(T); |
653 | template<typename T> int arg(T) = delete; // expected-note {{here}} expected-error 0-1{{extension}} |
654 | |
655 | void f(A::E e) { |
656 | foo(e, &arg); // expected-error {{no matching function}} |
657 | |
658 | using A::foo; |
659 | foo<int, int>(e, &arg); // expected-error {{deleted}} |
660 | } |
661 | |
662 | int arg(int); |
663 | |
664 | void g(A::E e) { |
665 | foo(e, &arg); // expected-error {{no matching function}} |
666 | |
667 | using A::foo; |
668 | foo<int, int>(e, &arg); // ok, uses non-template |
669 | } |
670 | } |
671 | |
672 | namespace contexts { |
673 | template<int I> void f1(int (&)[I]); |
674 | template<int I> void f2(int (&)[I+1]); // expected-note {{couldn't infer}} |
675 | template<int I> void f3(int (&)[I+1], int (&)[I]); |
676 | void f() { |
677 | int a[4]; |
678 | int b[3]; |
679 | f1(a); |
680 | f2(a); // expected-error {{no matching function}} |
681 | f3(a, b); |
682 | } |
683 | |
684 | template<int I> struct S {}; |
685 | template<int I> void g1(S<I>); |
686 | template<int I> void g2(S<I+1>); // expected-note {{couldn't infer}} |
687 | template<int I> void g3(S<I+1>, S<I>); |
688 | void g() { |
689 | S<4> a; |
690 | S<3> b; |
691 | g1(a); |
692 | g2(a); // expected-error {{no matching function}} |
693 | g3(a, b); |
694 | } |
695 | |
696 | template<typename T> void h1(T = 0); // expected-note {{couldn't infer}} |
697 | template<typename T> void h2(T, T = 0); |
698 | void h() { |
699 | h1(); // expected-error {{no matching function}} |
700 | h1(0); |
701 | h1<int>(); |
702 | h2(0); |
703 | } |
704 | |
705 | template<typename T> int tmpl(T); |
706 | template<typename R, typename A> void i1(R (*)(A)); // expected-note 3{{couldn't infer}} |
707 | template<typename R, typename A> void i2(R, A, R (*)(A)); // expected-note {{not viable}} |
708 | void i() { |
709 | extern int single(int); |
710 | i1(single); |
711 | i2(0, 0, single); |
712 | |
713 | extern int ambig(float), ambig(int); |
714 | i1(ambig); // expected-error {{no matching function}} |
715 | i2(0, 0, ambig); |
716 | |
717 | extern void no_match(float), no_match(int); |
718 | i1(no_match); // expected-error {{no matching function}} |
719 | i2(0, 0, no_match); // expected-error {{no matching function}} |
720 | |
721 | i1(tmpl); // expected-error {{no matching function}} |
722 | i2(0, 0, tmpl); |
723 | } |
724 | } |
725 | |
726 | template<typename T> struct is_int; |
727 | template<> struct is_int<int> {}; |
728 | |
729 | namespace example2 { |
730 | template<typename T> int f(T (*p)(T)) { is_int<T>(); } |
731 | int g(int); |
732 | int g(char); |
733 | int i = f(g); |
734 | } |
735 | |
736 | namespace example3 { |
737 | template<typename T> int f(T, T (*p)(T)) { is_int<T>(); } |
738 | int g(int); |
739 | char g(char); |
740 | int i = f(1, g); |
741 | } |
742 | |
743 | namespace example4 { |
744 | template <class T> int f(T, T (*p)(T)) { is_int<T>(); } |
745 | char g(char); |
746 | template <class T> T g(T); |
747 | int i = f(1, g); |
748 | } |
749 | |
750 | namespace example5 { |
751 | template<int I> class A {}; |
752 | template<int I> void g(A<I+1>); // expected-note {{couldn't infer}} |
753 | template<int I> void f(A<I>, A<I+1>); |
754 | void h(A<1> a1, A<2> a2) { |
755 | g(a1); // expected-error {{no matching function}} |
756 | g<0>(a1); |
757 | f(a1, a2); |
758 | } |
759 | } |
760 | } |
761 | |
762 | // dr353 needs an IRGen test. |
763 | |
764 | namespace dr354 { // dr354: yes c++11 |
765 | // FIXME: Should we allow this in C++98 too? |
766 | struct S {}; |
767 | |
768 | template<int*> struct ptr {}; // expected-note 0-4{{here}} |
769 | ptr<0> p0; |
770 | ptr<(int*)0> p1; |
771 | ptr<(float*)0> p2; |
772 | ptr<(int S::*)0> p3; |
773 | #if __cplusplus < 201103L |
774 | // expected-error@-5 {{does not refer to any decl}} |
775 | // expected-error@-5 {{does not refer to any decl}} |
776 | // expected-error@-5 {{does not refer to any decl}} |
777 | // expected-error@-5 {{does not refer to any decl}} |
778 | #elif __cplusplus <= 201402L |
779 | // expected-error@-10 {{must be cast}} |
780 | // ok |
781 | // expected-error@-10 {{does not match}} |
782 | // expected-error@-10 {{does not match}} |
783 | #else |
784 | // expected-error@-15 {{conversion from 'int' to 'int *' is not allowed}} |
785 | // ok |
786 | // expected-error@-15 {{'float *' is not implicitly convertible to 'int *'}} |
787 | // expected-error@-15 {{'int dr354::S::*' is not implicitly convertible to 'int *'}} |
788 | #endif |
789 | |
790 | template<int*> int both(); |
791 | template<int> int both(); |
792 | int b0 = both<0>(); |
793 | int b1 = both<(int*)0>(); |
794 | #if __cplusplus < 201103L |
795 | // expected-error@-2 {{no matching function}} |
796 | // expected-note@-6 {{candidate}} |
797 | // expected-note@-6 {{candidate}} |
798 | #endif |
799 | |
800 | template<int S::*> struct ptr_mem {}; // expected-note 0-4{{here}} |
801 | ptr_mem<0> m0; |
802 | ptr_mem<(int S::*)0> m1; |
803 | ptr_mem<(float S::*)0> m2; |
804 | ptr_mem<(int *)0> m3; |
805 | #if __cplusplus < 201103L |
806 | // expected-error@-5 {{cannot be converted}} |
807 | // expected-error@-5 {{is not a pointer to member constant}} |
808 | // expected-error@-5 {{cannot be converted}} |
809 | // expected-error@-5 {{cannot be converted}} |
810 | #elif __cplusplus <= 201402L |
811 | // expected-error@-10 {{must be cast}} |
812 | // ok |
813 | // expected-error@-10 {{does not match}} |
814 | // expected-error@-10 {{does not match}} |
815 | #else |
816 | // expected-error@-15 {{conversion from 'int' to 'int dr354::S::*' is not allowed}} |
817 | // ok |
818 | // expected-error@-15 {{'float dr354::S::*' is not implicitly convertible to 'int dr354::S::*'}} |
819 | // expected-error@-15 {{'int *' is not implicitly convertible to 'int dr354::S::*'}} |
820 | #endif |
821 | } |
822 | |
823 | struct dr355_S; // dr355: yes |
824 | struct ::dr355_S {}; // expected-warning {{extra qualification}} |
825 | namespace dr355 { struct ::dr355_S s; } |
826 | |
827 | // dr356: na |
828 | |
829 | namespace dr357 { // dr357: yes |
830 | template<typename T> struct A { |
831 | void f() const; // expected-note {{const qualified}} |
832 | }; |
833 | template<typename T> void A<T>::f() {} // expected-error {{does not match}} |
834 | |
835 | struct B { |
836 | template<typename T> void f(); |
837 | }; |
838 | template<typename T> void B::f() const {} // expected-error {{does not match}} |
839 | } |
840 | |
841 | namespace dr358 { // dr358: yes |
842 | extern "C" void dr358_f(); |
843 | namespace N { |
844 | int var; |
845 | extern "C" void dr358_f() { var = 10; } |
846 | } |
847 | } |
848 | |
849 | namespace dr359 { // dr359: yes |
850 | // Note, the example in the DR is wrong; it doesn't contain an anonymous |
851 | // union. |
852 | struct E { |
853 | union { |
854 | struct { |
855 | int x; |
856 | } s; |
857 | } v; |
858 | |
859 | union { |
860 | struct { // expected-error {{extension}} |
861 | int x; |
862 | } s; |
863 | |
864 | struct S { // expected-error {{types cannot be declared in an anonymous union}} |
865 | int x; |
866 | } t; |
867 | |
868 | union { // expected-error {{extension}} |
869 | int u; |
870 | }; |
871 | }; |
872 | }; |
873 | } |
874 | |
875 | // dr362: na |
876 | // dr363: na |
877 | |
878 | namespace dr364 { // dr364: yes |
879 | struct S { |
880 | static void f(int); |
881 | void f(char); |
882 | }; |
883 | |
884 | void g() { |
885 | S::f('a'); // expected-error {{call to non-static}} |
886 | S::f(0); |
887 | } |
888 | } |
889 | |
890 | #if "foo" // expected-error {{invalid token}} dr366: yes |
891 | #endif |
892 | |
893 | namespace dr367 { // dr367: yes |
894 | // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global |
895 | // array as being a VLA! |
896 | int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}} |
897 | int b[true ? 4 : throw 0]; |
898 | int c[true ? *new int : 4]; // expected-error 2{{variable length array}} |
899 | int d[true ? 4 : *new int]; |
900 | #if __cplusplus < 201103L |
901 | // expected-error@-4 {{variable length array}} expected-error@-4 {{constant expression}} |
902 | // expected-error@-3 {{variable length array}} expected-error@-3 {{constant expression}} |
903 | #endif |
904 | } |
905 | |
906 | namespace dr368 { // dr368: yes |
907 | template<typename T, T> struct S {}; // expected-note {{here}} |
908 | template<typename T> int f(S<T, T()> *); // expected-error {{function type}} |
909 | //template<typename T> int g(S<T, (T())> *); // FIXME: crashes clang |
910 | template<typename T> int g(S<T, true ? T() : T()> *); // expected-note {{cannot have type 'dr368::X'}} |
911 | struct X {}; |
912 | int n = g<X>(0); // expected-error {{no matching}} |
913 | } |
914 | |
915 | // dr370: na |
916 | |
917 | namespace dr372 { // dr372: no |
918 | namespace example1 { |
919 | template<typename T> struct X { |
920 | protected: |
921 | typedef T Type; // expected-note 2{{protected}} |
922 | }; |
923 | template<typename T> struct Y {}; |
924 | |
925 | // FIXME: These two are valid; deriving from T1<T> gives Z1 access to |
926 | // the protected member T1<T>::Type. |
927 | template<typename T, |
928 | template<typename> class T1, |
929 | template<typename> class T2> struct Z1 : |
930 | T1<T>, |
931 | T2<typename T1<T>::Type> {}; // expected-error {{protected}} |
932 | |
933 | template<typename T, |
934 | template<typename> class T1, |
935 | template<typename> class T2> struct Z2 : |
936 | T2<typename T1<T>::Type>, // expected-error {{protected}} |
937 | T1<T> {}; |
938 | |
939 | Z1<int, X, Y> z1; // expected-note {{instantiation of}} |
940 | Z2<int, X, Y> z2; // expected-note {{instantiation of}} |
941 | } |
942 | |
943 | namespace example2 { |
944 | struct X { |
945 | private: |
946 | typedef int Type; // expected-note {{private}} |
947 | }; |
948 | template<typename T> struct A { |
949 | typename T::Type t; // expected-error {{private}} |
950 | }; |
951 | A<X> ax; // expected-note {{instantiation of}} |
952 | } |
953 | |
954 | namespace example3 { |
955 | struct A { |
956 | protected: |
957 | typedef int N; // expected-note 2{{protected}} |
958 | }; |
959 | |
960 | template<typename T> struct B {}; |
961 | template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}} |
962 | template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}} |
963 | |
964 | C<A> x; // expected-note {{instantiation of}} |
965 | D<A> y; // expected-note {{instantiation of}} |
966 | } |
967 | |
968 | namespace example4 { |
969 | class A { |
970 | class B {}; |
971 | friend class X; |
972 | }; |
973 | |
974 | struct X : A::B { |
975 | A::B mx; |
976 | class Y { |
977 | A::B my; |
978 | }; |
979 | }; |
980 | } |
981 | |
982 | // FIXME: This is valid: deriving from A gives D access to A::B |
983 | namespace std_example { |
984 | class A { |
985 | protected: |
986 | struct B {}; // expected-note {{here}} |
987 | }; |
988 | struct D : A::B, A {}; // expected-error {{protected}} |
989 | } |
990 | |
991 | // FIXME: This is valid: deriving from A::B gives access to A::B! |
992 | namespace badwolf { |
993 | class A { |
994 | protected: |
995 | struct B; // expected-note {{here}} |
996 | }; |
997 | struct A::B : A {}; |
998 | struct C : A::B {}; // expected-error {{protected}} |
999 | } |
1000 | } |
1001 | |
1002 | namespace dr373 { // dr373: 5 |
1003 | namespace X { int dr373; } |
1004 | struct dr373 { // expected-note {{here}} |
1005 | void f() { |
1006 | using namespace dr373::X; |
1007 | int k = dr373; // expected-error {{does not refer to a value}} |
1008 | |
1009 | namespace Y = dr373::X; |
1010 | k = Y::dr373; |
1011 | } |
1012 | }; |
1013 | |
1014 | struct A { struct B {}; }; // expected-note 2{{here}} |
1015 | namespace X = A::B; // expected-error {{expected namespace name}} |
1016 | using namespace A::B; // expected-error {{expected namespace name}} |
1017 | } |
1018 | |
1019 | namespace dr374 { // dr374: yes |
1020 | namespace N { |
1021 | template<typename T> void f(); |
1022 | template<typename T> struct A { void f(); }; |
1023 | } |
1024 | template<> void N::f<char>() {} |
1025 | template<> void N::A<char>::f() {} |
1026 | template<> struct N::A<int> {}; |
1027 | } |
1028 | |
1029 | // dr375: dup 345 |
1030 | // dr376: na |
1031 | |
1032 | namespace dr377 { // dr377: yes |
1033 | enum E { // expected-error {{enumeration values exceed range of largest integer}} |
1034 | a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}} |
1035 | b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}} |
1036 | }; |
1037 | } |
1038 | |
1039 | // dr378: dup 276 |
1040 | // dr379: na |
1041 | |
1042 | namespace dr381 { // dr381: yes |
1043 | struct A { |
1044 | int a; |
1045 | }; |
1046 | struct B : virtual A {}; |
1047 | struct C : B {}; |
1048 | struct D : B {}; |
1049 | struct E : public C, public D {}; |
1050 | struct F : public A {}; |
1051 | void f() { |
1052 | E e; |
1053 | e.B::a = 0; // expected-error {{ambiguous conversion}} |
1054 | F f; |
1055 | f.A::a = 1; |
1056 | } |
1057 | } |
1058 | |
1059 | namespace dr382 { // dr382: yes c++11 |
1060 | // FIXME: Should we allow this in C++98 mode? |
1061 | struct A { typedef int T; }; |
1062 | typename A::T t; |
1063 | typename dr382::A a; |
1064 | #if __cplusplus < 201103L |
1065 | // expected-error@-3 {{occurs outside of a template}} |
1066 | // expected-error@-3 {{occurs outside of a template}} |
1067 | #endif |
1068 | typename A b; // expected-error {{expected a qualified name}} |
1069 | } |
1070 | |
1071 | namespace dr383 { // dr383: yes |
1072 | struct A { A &operator=(const A&); }; |
1073 | struct B { ~B(); }; |
1074 | union C { C &operator=(const C&); }; |
1075 | union D { ~D(); }; |
1076 | int check[(__is_pod(A) || __is_pod(B) || __is_pod(C) || __is_pod(D)) ? -1 : 1]; |
1077 | } |
1078 | |
1079 | namespace dr384 { // dr384: yes |
1080 | namespace N1 { |
1081 | template<typename T> struct Base {}; |
1082 | template<typename T> struct X { |
1083 | struct Y : public Base<T> { |
1084 | Y operator+(int) const; |
1085 | }; |
1086 | Y f(unsigned i) { return Y() + i; } |
1087 | }; |
1088 | } |
1089 | |
1090 | namespace N2 { |
1091 | struct Z {}; |
1092 | template<typename T> int *operator+(T, unsigned); |
1093 | } |
1094 | |
1095 | int main() { |
1096 | N1::X<N2::Z> v; |
1097 | v.f(0); |
1098 | } |
1099 | } |
1100 | |
1101 | namespace dr385 { // dr385: yes |
1102 | struct A { protected: void f(); }; |
1103 | struct B : A { using A::f; }; |
1104 | struct C : A { void g(B b) { b.f(); } }; |
1105 | void h(B b) { b.f(); } |
1106 | |
1107 | struct D { int n; }; // expected-note {{member}} |
1108 | struct E : protected D {}; // expected-note 2{{protected}} |
1109 | struct F : E { friend int i(E); }; |
1110 | int i(E e) { return e.n; } // expected-error {{protected base}} expected-error {{protected member}} |
1111 | } |
1112 | |
1113 | namespace dr387 { // dr387: yes |
1114 | namespace old { |
1115 | template<typename T> class number { |
1116 | number(int); // expected-note 2{{here}} |
1117 | friend number gcd(number &x, number &y) {} |
1118 | }; |
1119 | |
1120 | void g() { |
1121 | number<double> a(3), b(4); // expected-error 2{{private}} |
1122 | a = gcd(a, b); |
1123 | b = gcd(3, 4); // expected-error {{undeclared}} |
1124 | } |
1125 | } |
1126 | |
1127 | namespace newer { |
1128 | template <typename T> class number { |
1129 | public: |
1130 | number(int); |
1131 | friend number gcd(number x, number y) { return 0; } |
1132 | }; |
1133 | |
1134 | void g() { |
1135 | number<double> a(3), b(4); |
1136 | a = gcd(a, b); |
1137 | b = gcd(3, 4); // expected-error {{undeclared}} |
1138 | } |
1139 | } |
1140 | } |
1141 | |
1142 | // FIXME: dr388 needs codegen test |
1143 | |
1144 | namespace dr389 { // dr389: no |
1145 | struct S { |
1146 | typedef struct {} A; |
1147 | typedef enum {} B; |
1148 | typedef struct {} const C; // expected-note 0-2{{here}} |
1149 | typedef enum {} const D; // expected-note 0-1{{here}} |
1150 | }; |
1151 | template<typename> struct T {}; |
1152 | |
1153 | struct WithLinkage1 {}; |
1154 | enum WithLinkage2 {}; |
1155 | typedef struct {} *WithLinkage3a, WithLinkage3b; |
1156 | typedef enum {} WithLinkage4a, *WithLinkage4b; |
1157 | typedef S::A WithLinkage5; |
1158 | typedef const S::B WithLinkage6; |
1159 | typedef int WithLinkage7; |
1160 | typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *); |
1161 | typedef T<WithLinkage5> WithLinkage9; |
1162 | |
1163 | typedef struct {} *WithoutLinkage1; // expected-note 0-1{{here}} |
1164 | typedef enum {} const WithoutLinkage2; // expected-note 0-1{{here}} |
1165 | // These two types don't have linkage even though they are externally visible |
1166 | // and the ODR requires them to be merged across TUs. |
1167 | typedef S::C WithoutLinkage3; |
1168 | typedef S::D WithoutLinkage4; |
1169 | typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char)); |
1170 | |
1171 | #if __cplusplus >= 201103L |
1172 | // This has linkage even though its template argument does not. |
1173 | // FIXME: This is probably a defect. |
1174 | typedef T<WithoutLinkage1> WithLinkage10; |
1175 | #else |
1176 | typedef int WithLinkage10; // dummy |
1177 | |
1178 | typedef T<WithLinkage1> GoodArg1; |
1179 | typedef T<WithLinkage2> GoodArg2; |
1180 | typedef T<WithLinkage3a> GoodArg3a; |
1181 | typedef T<WithLinkage3b> GoodArg3b; |
1182 | typedef T<WithLinkage4a> GoodArg4a; |
1183 | typedef T<WithLinkage4b> GoodArg4b; |
1184 | typedef T<WithLinkage5> GoodArg5; |
1185 | typedef T<WithLinkage6> GoodArg6; |
1186 | typedef T<WithLinkage7> GoodArg7; |
1187 | typedef T<WithLinkage8> GoodArg8; |
1188 | typedef T<WithLinkage9> GoodArg9; |
1189 | |
1190 | typedef T<WithoutLinkage1> BadArg1; // expected-error{{template argument uses}} |
1191 | typedef T<WithoutLinkage2> BadArg2; // expected-error{{template argument uses}} |
1192 | typedef T<WithoutLinkage3> BadArg3; // expected-error{{template argument uses}} |
1193 | typedef T<WithoutLinkage4> BadArg4; // expected-error{{template argument uses}} |
1194 | typedef T<WithoutLinkage5> BadArg5; // expected-error{{template argument uses}} |
1195 | #endif |
1196 | |
1197 | extern WithLinkage1 withLinkage1; |
1198 | extern WithLinkage2 withLinkage2; |
1199 | extern WithLinkage3a withLinkage3a; |
1200 | extern WithLinkage3b withLinkage3b; |
1201 | extern WithLinkage4a withLinkage4a; |
1202 | extern WithLinkage4b withLinkage4b; |
1203 | extern WithLinkage5 withLinkage5; |
1204 | extern WithLinkage6 withLinkage6; |
1205 | extern WithLinkage7 withLinkage7; |
1206 | extern WithLinkage8 withLinkage8; |
1207 | extern WithLinkage9 withLinkage9; |
1208 | extern WithLinkage10 withLinkage10; |
1209 | |
1210 | // FIXME: These are all ill-formed. |
1211 | extern WithoutLinkage1 withoutLinkage1; |
1212 | extern WithoutLinkage2 withoutLinkage2; |
1213 | extern WithoutLinkage3 withoutLinkage3; |
1214 | extern WithoutLinkage4 withoutLinkage4; |
1215 | extern WithoutLinkage5 withoutLinkage5; |
1216 | |
1217 | // OK, extern "C". |
1218 | extern "C" { |
1219 | extern WithoutLinkage1 dr389_withoutLinkage1; |
1220 | extern WithoutLinkage2 dr389_withoutLinkage2; |
1221 | extern WithoutLinkage3 dr389_withoutLinkage3; |
1222 | extern WithoutLinkage4 dr389_withoutLinkage4; |
1223 | extern WithoutLinkage5 dr389_withoutLinkage5; |
1224 | } |
1225 | |
1226 | // OK, defined. |
1227 | WithoutLinkage1 withoutLinkageDef1; |
1228 | WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2(); |
1229 | WithoutLinkage3 withoutLinkageDef3 = {}; |
1230 | WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4(); |
1231 | WithoutLinkage5 withoutLinkageDef5; |
1232 | |
1233 | void use(const void *); |
1234 | void use_all() { |
1235 | use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b); |
1236 | use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6); |
1237 | use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10); |
1238 | |
1239 | use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3); |
1240 | use(&withoutLinkage4); use(&withoutLinkage5); |
1241 | |
1242 | use(&dr389_withoutLinkage1); use(&dr389_withoutLinkage2); |
1243 | use(&dr389_withoutLinkage3); use(&dr389_withoutLinkage4); |
1244 | use(&dr389_withoutLinkage5); |
1245 | |
1246 | use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3); |
1247 | use(&withoutLinkageDef4); use(&withoutLinkageDef5); |
1248 | } |
1249 | |
1250 | void local() { |
1251 | // FIXME: This is ill-formed. |
1252 | extern WithoutLinkage1 withoutLinkageLocal; |
1253 | } |
1254 | } |
1255 | |
1256 | namespace dr390 { // dr390: yes |
1257 | template<typename T> |
1258 | struct A { |
1259 | A() { f(); } // expected-warning {{call to pure virt}} |
1260 | virtual void f() = 0; // expected-note {{here}} |
1261 | virtual ~A() = 0; |
1262 | }; |
1263 | template<typename T> A<T>::~A() { T::error; } // expected-error {{cannot be used prior to}} |
1264 | template<typename T> void A<T>::f() { T::error; } // ok, not odr-used |
1265 | struct B : A<int> { // expected-note 2{{in instantiation of}} |
1266 | void f() {} |
1267 | } b; |
1268 | } |
1269 | |
1270 | namespace dr391 { // dr391: yes c++11 |
1271 | // FIXME: Should this apply to C++98 too? |
1272 | class A { A(const A&); }; // expected-note 0-1{{here}} |
1273 | A fa(); |
1274 | const A &a = fa(); |
1275 | #if __cplusplus < 201103L |
1276 | // expected-error@-2 {{C++98 requires an accessible copy constructor}} |
1277 | #endif |
1278 | |
1279 | struct B { B(const B&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}} |
1280 | B fb(); |
1281 | const B &b = fb(); |
1282 | #if __cplusplus < 201103L |
1283 | // expected-error@-2 {{deleted}} |
1284 | #endif |
1285 | |
1286 | template<typename T> |
1287 | struct C { |
1288 | C(const C&) { T::error; } |
1289 | }; |
1290 | C<int> fc(); |
1291 | const C<int> &c = fc(); |
1292 | } |
1293 | |
1294 | // dr392 FIXME write codegen test |
1295 | // dr394: na |
1296 | |
1297 | namespace dr395 { // dr395: yes |
1298 | struct S { |
1299 | template <typename T, int N>(&operator T())[N]; // expected-error {{cannot specify any part of a return type}} |
1300 | template <typename T, int N> operator(T (&)[N])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}} |
1301 | template <typename T> operator T *() const { return 0; } |
1302 | template <typename T, typename U> operator T U::*() const { return 0; } |
1303 | template <typename T, typename U> operator T (U::*)()() const { return 0; } // expected-error +{{}} |
1304 | }; |
1305 | |
1306 | struct null1_t { |
1307 | template <class T, class U> struct ptr_mem_fun_t { |
1308 | typedef T (U::*type)(); |
1309 | }; |
1310 | |
1311 | template <class T, class U> |
1312 | operator typename ptr_mem_fun_t<T, U>::type() const { // expected-note {{couldn't infer}} |
1313 | return 0; |
1314 | } |
1315 | } null1; |
1316 | int (S::*p)() = null1; // expected-error {{no viable conversion}} |
1317 | |
1318 | template <typename T> using id = T; // expected-error 0-1{{extension}} |
1319 | |
1320 | struct T { |
1321 | template <typename T, int N> operator id<T[N]> &(); |
1322 | template <typename T, typename U> operator id<T (U::*)()>() const; |
1323 | }; |
1324 | |
1325 | struct null2_t { |
1326 | template<class T, class U> using ptr_mem_fun_t = T (U::*)(); // expected-error 0-1{{extension}} |
1327 | template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; }; |
1328 | } null2; |
1329 | int (S::*q)() = null2; |
1330 | } |
1331 | |
1332 | namespace dr396 { // dr396: yes |
1333 | void f() { |
1334 | auto int a(); // expected-error {{storage class on function}} |
1335 | int (i); // expected-note {{previous}} |
1336 | auto int (i); // expected-error {{redefinition}} |
1337 | #if __cplusplus >= 201103L |
1338 | // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}} |
1339 | #endif |
1340 | } |
1341 | } |
1342 | |
1343 | // dr397: sup 1823 |
1344 | |
1345 | namespace dr398 { // dr398: yes |
1346 | namespace example1 { |
1347 | struct S { |
1348 | static int const I = 42; |
1349 | }; |
1350 | template <int N> struct X {}; |
1351 | template <typename T> void f(X<T::I> *) {} |
1352 | template <typename T> void f(X<T::J> *) {} |
1353 | void foo() { f<S>(0); } |
1354 | } |
1355 | |
1356 | namespace example2 { |
1357 | template <int I> struct X {}; |
1358 | template <template <class T> class> struct Z {}; |
1359 | template <class T> void f(typename T::Y *) {} // expected-note 2{{substitution failure}} |
1360 | template <class T> void g(X<T::N> *) {} // expected-note {{substitution failure}} |
1361 | template <class T> void h(Z<T::template TT> *) {} // expected-note {{substitution failure}} |
1362 | struct A {}; |
1363 | struct B { |
1364 | int Y; |
1365 | }; |
1366 | struct C { |
1367 | typedef int N; |
1368 | }; |
1369 | struct D { |
1370 | typedef int TT; |
1371 | }; |
1372 | |
1373 | void test() { |
1374 | f<A>(0); // expected-error {{no matching function}} |
1375 | f<B>(0); // expected-error {{no matching function}} |
1376 | g<C>(0); // expected-error {{no matching function}} |
1377 | h<D>(0); // expected-error {{no matching function}} |
1378 | } |
1379 | } |
1380 | } |
1381 | |