/
dr3xx.cpp
1428 lines (1234 loc) · 41.7 KB
/
dr3xx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// RUN: %clang_cc1 -std=c++2b -verify=expected,cxx20_2b,cxx2b -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98_20,cxx20_2b -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
namespace dr300 { // dr300: yes
template<typename R, typename A> void f(R (&)(A)) {}
int g(int);
void h() { f(g); }
}
namespace dr301 { // dr301: yes
// see also dr38
struct S;
template<typename T> void operator+(T, T);
void operator-(S, S);
void f() {
bool a = (void(*)(S, S))operator+<S> < // expected-warning {{ordered comparison of function pointers}}
(void(*)(S, S))operator+<S>;
bool b = (void(*)(S, S))operator- < // cxx20_2b-note {{to match this '<'}} cxx98_17-warning {{ordered comparison of function pointers}}
(void(*)(S, S))operator-; // cxx20_2b-error {{expected '>'}}
bool c = (void(*)(S, S))operator+ < // expected-note {{to match this '<'}}
(void(*)(S, S))operator-; // expected-error {{expected '>'}}
}
template<typename T> void f() {
typename T::template operator+<int> a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
// FIXME: This shouldn't say (null).
class T::template operator+<int> b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
enum T::template operator+<int> c; // expected-error {{expected identifier}}
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}}
enum T::template X<int>::E e;
T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}}
T::template operator+<int>(0); // ok
}
template<typename T> class operator&<T*> {}; // expected-error +{{}}
template<typename T> class T::operator& {}; // expected-error +{{}}
template<typename T> class S::operator&<T*> {}; // expected-error +{{}}
}
namespace dr302 { // dr302: yes
struct A { A(); ~A(); };
#if __cplusplus < 201103L
struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}}
const int n; // expected-note {{declared here}}
A a;
} b = B(); // expected-note {{first required here}}
// Trivial default constructor C::C() is not called here.
struct C {
const int n;
} c = C();
#else
struct B {
const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
A a;
} b = B(); // expected-error {{call to implicitly-deleted default constructor}}
// C::C() is called here, because even though it's trivial, it's deleted.
struct C {
const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
} c = C(); // expected-error {{call to implicitly-deleted default constructor}}
struct D {
const int n = 0;
} d = D();
#endif
}
// dr303: na
namespace dr304 { // dr304: yes
typedef int &a;
int n = a(); // expected-error {{requires an initializer}}
struct S { int &b; };
int m = S().b;
#if __cplusplus < 201103L
// expected-error@-3 {{requires an initializer}}
// expected-note@-3 {{in value-initialization}}
#else
// expected-error@-5 {{deleted}}
// expected-note@-7 {{reference}}
#endif
}
namespace dr305 { // dr305: no
struct A {
typedef A C;
};
void f(A *a) {
struct A {};
a->~A();
a->~C();
}
typedef A B;
void g(B *b) {
b->~B();
b->~C();
}
void h(B *b) {
struct B {}; // expected-note {{type 'B' found by destructor name lookup}}
b->~B(); // expected-error {{does not match}}
}
template<typename T> struct X {};
void i(X<int>* x) {
struct X {};
x->~X<int>();
x->~X();
x->~X<char>(); // expected-error {{no member named}}
}
#if __cplusplus >= 201103L
struct Y {
template<typename T> using T1 = Y;
};
template<typename T> using T2 = Y;
void j(Y *y) {
y->~T1<int>();
y->~T2<int>();
}
struct Z {
template<typename T> using T2 = T;
};
void k(Z *z) {
z->~T1<int>(); // expected-error {{no member named 'T1' in 'dr305::Z'}}
z->~T2<int>(); // expected-error {{no member named '~int'}}
z->~T2<Z>();
}
// FIXME: This is valid.
namespace Q {
template<typename A> struct R {};
}
template<typename A> using R = Q::R<int>;
void qr(Q::R<int> x) { x.~R<char>(); } // expected-error {{no member named}}
#endif
}
namespace dr306 { // dr306: dup 39
struct A { struct B {}; };
struct C { typedef A::B B; };
struct D : A, A::B, C {};
D::B b;
struct X {}; // expected-note {{member type 'dr306::X' found}}
template<typename T> struct Y { typedef T X; }; // expected-note {{member type 'const dr306::X' found}}
template<typename T> struct Z : X, Y<T> {};
Z<X>::X zx;
Z<const X>::X zcx; // expected-error {{member 'X' found in multiple base classes of different types}}
}
// dr307: na
namespace dr308 { // dr308: yes
// This is mostly an ABI library issue.
struct A {};
struct B : A {};
struct C : A {};
struct D : B, C {};
void f() {
try {
throw D();
} catch (const A&) { // expected-note {{for type 'const A &'}}
// unreachable
} catch (const B&) { // expected-warning {{exception of type 'const B &' will be caught by earlier handler}}
// get here instead
}
}
}
// dr309: dup 485
namespace dr311 { // dr311: yes
namespace X { namespace Y {} }
namespace X::Y {}
#if __cplusplus <= 201402L
// expected-error@-2 {{define each namespace separately}}
#endif
namespace X {
namespace X::Y {}
#if __cplusplus <= 201402L
// expected-error@-2 {{define each namespace separately}}
#endif
}
// FIXME: The diagnostics here are not very good.
namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}}
}
// dr312: dup 616
namespace dr313 { // dr313: dup 299 c++11
struct A { operator int() const; };
int *p = new int[A()];
#if __cplusplus < 201103L
// FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}}
#endif
}
namespace dr314 { // FIXME 314: dup 1710
template<typename T> struct A {
template<typename U> struct B {};
};
template<typename T> struct C : public A<T>::template B<T> {
C() : A<T>::template B<T>() {}
};
}
// dr315: na
// dr316: sup 1004
namespace dr317 { // dr317: 3.5
void f() {} // expected-note {{previous}}
inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}}
int g();
int n = g();
inline int g() { return 0; }
int h();
int m = h();
int h() { return 0; } // expected-note {{previous}}
inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}}
}
namespace dr318 { // dr318: sup 1310
struct A {};
struct A::A a;
}
namespace dr319 { // dr319: no
// FIXME: dup dr389
// FIXME: We don't have a diagnostic for a name with linkage
// having a type without linkage.
typedef struct {
int i;
} *ps;
extern "C" void f(ps);
void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
static enum { e } a1;
enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
enum { n1 = 1u };
typedef int (*pa)[n1];
pa parr; // ok, type has linkage despite using 'n1'
template<typename> struct X {};
void f() {
struct A { int n; };
extern A a; // FIXME: ill-formed
X<A> xa;
typedef A B;
extern B b; // FIXME: ill-formed
X<B> xb;
const int n = 1;
typedef int (*C)[n];
extern C c; // ok
X<C> xc;
}
#if __cplusplus < 201103L
// expected-error@-12 {{uses local type 'A'}}
// expected-error@-9 {{uses local type 'A'}}
#endif
}
namespace dr320 { // dr320: yes
#if __cplusplus >= 201103L
struct X {
constexpr X() {}
constexpr X(const X &x) : copies(x.copies + 1) {}
unsigned copies = 0;
};
constexpr X f(X x) { return x; }
constexpr unsigned g(X x) { return x.copies; }
static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value");
#endif
}
namespace dr321 { // dr321: dup 557
namespace N {
template<int> struct A {
template<int> struct B;
};
template<> template<> struct A<0>::B<0>;
void f(A<0>::B<0>);
}
template<> template<> struct N::A<0>::B<0> {};
template<typename T> void g(T t) { f(t); }
template void g(N::A<0>::B<0>);
namespace N {
template<typename> struct I { friend bool operator==(const I&, const I&); };
}
N::I<int> i, j;
bool x = i == j;
}
namespace dr322 { // dr322: yes
struct A {
template<typename T> operator T&();
} a;
int &r = static_cast<int&>(a);
int &s = a;
}
// dr323: no
namespace dr324 { // dr324: yes
struct S { int n : 1; } s; // expected-note 3{{bit-field is declared here}}
int &a = s.n; // expected-error {{non-const reference cannot bind to bit-field}}
int *b = &s.n; // expected-error {{address of bit-field}}
int &c = (s.n = 0); // expected-error {{non-const reference cannot bind to bit-field}}
int *d = &(s.n = 0); // expected-error {{address of bit-field}}
int &e = true ? s.n : s.n; // expected-error {{non-const reference cannot bind to bit-field}}
int *f = &(true ? s.n : s.n); // expected-error {{address of bit-field}}
int &g = (void(), s.n); // expected-error {{non-const reference cannot bind to bit-field}}
int *h = &(void(), s.n); // expected-error {{address of bit-field}}
int *i = &++s.n; // expected-error {{address of bit-field}}
}
namespace dr326 { // dr326: yes
struct S {};
int test[__is_trivially_constructible(S, const S&) ? 1 : -1];
}
namespace dr327 { // dr327: dup 538
struct A;
class A {};
class B;
struct B {};
}
namespace dr328 { // dr328: yes
struct A; // expected-note 3{{forward declaration}}
struct B { A a; }; // expected-error {{incomplete}}
template<typename> struct C { A a; }; // expected-error {{incomplete}}
A *p = new A[0]; // expected-error {{incomplete}}
}
namespace dr329 { // dr329: 3.5
struct B {};
template<typename T> struct A : B {
friend void f(A a) { g(a); }
friend void h(A a) { g(a); } // expected-error {{undeclared}}
friend void i(B b) {} // expected-error {{redefinition}} expected-note {{previous}}
};
A<int> a;
A<char> b; // expected-note {{instantiation}}
void test() {
h(a); // expected-note {{instantiation}}
}
}
namespace dr330 { // dr330: 7
// Conversions between P and Q will be allowed by P0388.
typedef int *(*P)[3];
typedef const int *const (*Q)[3];
typedef const int *Qinner[3];
typedef Qinner const *Q2; // same as Q, but 'const' written outside the array type
typedef const int *const (*R)[4];
typedef const int *const (*S)[];
typedef const int *(*T)[];
void f(P p, Q q, Q2 q2, R r, S s, T t) {
q = p; // ok
q2 = p; // ok
r = p; // expected-error {{incompatible}}
s = p;
#if __cplusplus < 202002
// expected-error@-2 {{incompatible}} (fixed by p0388)
#endif
t = p; // expected-error {{incompatible}}
s = q;
#if __cplusplus < 202002
// expected-error@-2 {{incompatible}} (fixed by p0388)
#endif
s = q2;
#if __cplusplus < 202002
// expected-error@-2 {{incompatible}} (fixed by p0388)
#endif
s = t; // ok, adding const
t = s; // expected-error {{discards qualifiers}}
(void) const_cast<P>(q);
(void) const_cast<P>(q2);
(void) const_cast<Q>(p);
(void) const_cast<Q2>(p);
(void) const_cast<S>(p); // expected-error {{not allowed}} (for now)
(void) const_cast<P>(s); // expected-error {{not allowed}} (for now)
(void) const_cast<S>(q); // expected-error {{not allowed}}
(void) const_cast<S>(q2); // expected-error {{not allowed}}
(void) const_cast<Q>(s); // expected-error {{not allowed}}
(void) const_cast<Q2>(s); // expected-error {{not allowed}}
(void) const_cast<T>(s);
(void) const_cast<S>(t);
(void) const_cast<T>(q); // expected-error {{not allowed}}
(void) const_cast<Q>(t); // expected-error {{not allowed}}
(void) reinterpret_cast<P>(q); // expected-error {{casts away qualifiers}}
(void) reinterpret_cast<P>(q2); // expected-error {{casts away qualifiers}}
(void) reinterpret_cast<Q>(p);
(void) reinterpret_cast<Q2>(p);
(void) reinterpret_cast<S>(p);
(void) reinterpret_cast<P>(s); // expected-error {{casts away qualifiers}}
(void) reinterpret_cast<S>(q);
(void) reinterpret_cast<S>(q2);
(void) reinterpret_cast<Q>(s);
(void) reinterpret_cast<Q2>(s);
(void) reinterpret_cast<T>(s); // expected-error {{casts away qualifiers}}
(void) reinterpret_cast<S>(t);
(void) reinterpret_cast<T>(q); // expected-error {{casts away qualifiers}}
(void) reinterpret_cast<Q>(t);
}
namespace swift_17882 {
typedef const char P[72];
typedef int *Q;
void f(P &pr, P *pp) {
(void) reinterpret_cast<const Q&>(pr);
(void) reinterpret_cast<const Q*>(pp);
}
struct X {};
typedef const volatile int A[1][2][3];
typedef int *const X::*volatile *B1;
typedef int *const X::* *B2;
typedef int *X::* volatile *B3;
typedef volatile int *(*const B4)[4];
void f(A *a) {
(void) reinterpret_cast<B1*>(a);
(void) reinterpret_cast<B2*>(a); // expected-error {{casts away qualifiers}}
(void) reinterpret_cast<B3*>(a); // expected-error {{casts away qualifiers}}
(void) reinterpret_cast<B4*>(a);
}
}
}
namespace dr331 { // dr331: yes
struct A {
A(volatile A&); // expected-note 2{{candidate}}
} const a, b(a); // expected-error 2{{no matching constructor}}
}
namespace dr332 { // dr332: dup 577
void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}}
// cxx20_2b-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}}
void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}}
void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}}
// cxx20_2b-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}}
}
namespace dr333 { // dr333: yes
int n = 0;
int f(int(n));
int g((int(n)));
int h = f(g);
}
namespace dr334 { // dr334: yes
template<typename T> void f() {
T x;
f((x, 123));
}
struct S {
friend S operator,(S, int);
friend void f(S);
};
template void f<S>();
}
// dr335: no
namespace dr336 { // dr336: yes
namespace Pre {
template<class T1> class A {
template<class T2> class B {
template<class T3> void mf1(T3);
void mf2();
};
};
template<> template<class X> class A<int>::B {};
template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} // expected-error {{does not match}}
template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
}
namespace Post {
template<class T1> class A {
template<class T2> class B {
template<class T3> void mf1(T3);
void mf2();
};
};
template<> template<class X> class A<int>::B {
template<class T> void mf1(T);
};
template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
// FIXME: This diagnostic isn't very good.
template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
}
}
namespace dr337 { // dr337: yes
template<typename T> void f(T (*)[1]);
template<typename T> int &f(...);
struct A { virtual ~A() = 0; };
int &r = f<A>(0);
// FIXME: The language rules here are completely broken. We cannot determine
// whether an incomplete type is abstract. See DR1640, which will probably
// supersede this one and remove this rule.
struct B;
int &s = f<B>(0); // expected-error {{of type 'void'}}
struct B { virtual ~B() = 0; };
}
namespace dr339 { // dr339: yes
template <int I> struct A { static const int value = I; };
char xxx(int);
char (&xxx(float))[2];
template<class T> A<sizeof(xxx((T)0))> f(T) {} // expected-note {{candidate}}
void test() {
A<1> a = f(0);
A<2> b = f(0.0f);
A<3> c = f("foo"); // expected-error {{no matching function}}
}
char f(int);
int f(...);
template <class T> struct conv_int {
static const bool value = sizeof(f(T())) == 1;
};
template <class T> bool conv_int2(A<sizeof(f(T()))> p);
template<typename T> A<sizeof(f(T()))> make_A();
int a[conv_int<char>::value ? 1 : -1];
bool b = conv_int2<char>(A<1>());
A<1> c = make_A<char>();
}
namespace dr340 { // dr340: yes
struct A { A(int); };
struct B { B(A, A, int); };
int x, y;
B b(A(x), A(y), 3);
}
namespace dr341 { // dr341: sup 1708
namespace A {
int n;
extern "C" int &dr341_a = n; // expected-note {{previous}} expected-note {{declared with C language linkage here}}
}
namespace B {
extern "C" int &dr341_a = dr341_a; // expected-error {{redefinition}}
}
extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}}
}
int dr341_a; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}}
int dr341_b; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}}
int dr341_c; // expected-note {{declared in global scope here}}
int dr341_d; // expected-note {{declared in global scope here}}
namespace dr341 {
extern "C" int dr341_c; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}}
extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}}
namespace A { extern "C" int dr341_e; } // expected-note {{previous}}
namespace B { extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}}
}
// dr342: na
namespace dr343 { // FIXME 343: no
// FIXME: dup 1710
template<typename T> struct A {
template<typename U> struct B {};
};
// FIXME: In these contexts, the 'template' keyword is optional.
template<typename T> struct C : public A<T>::B<T> { // expected-error {{use 'template'}}
C() : A<T>::B<T>() {} // expected-error {{use 'template'}}
};
}
namespace dr344 { // dr344: dup 1435
struct A { inline virtual ~A(); };
struct B { friend A::~A(); };
}
namespace dr345 { // dr345: yes
struct A {
struct X {};
int X; // expected-note {{here}}
};
struct B {
struct X {};
};
template <class T> void f(T t) { typename T::X x; } // expected-error {{refers to non-type member 'X'}}
void f(A a, B b) {
f(b);
f(a); // expected-note {{instantiation}}
}
}
// dr346: na
namespace dr347 { // dr347: yes
struct base {
struct nested;
static int n;
static void f();
void g();
};
struct derived : base {};
struct derived::nested {}; // expected-error {{no struct named 'nested'}}
int derived::n; // expected-error {{no member named 'n'}}
void derived::f() {} // expected-error {{does not match any}}
void derived::g() {} // expected-error {{does not match any}}
}
// dr348: na
namespace dr349 { // dr349: no
struct A {
template <class T> operator T ***() {
int ***p = 0;
return p; // cxx98_20-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
// cxx2b-error@-1 {{cannot initialize return object of type 'const int ***' with an rvalue of type 'int ***'}}
}
};
// FIXME: This is valid.
A a;
const int *const *const *p1 = a; // expected-note {{in instantiation of}}
struct B {
template <class T> operator T ***() {
const int ***p = 0;
return p;
}
};
// FIXME: This is invalid.
B b;
const int *const *const *p2 = b;
}
// dr351: na
namespace dr352 { // dr352: yes
namespace example1 {
namespace A {
enum E {};
template<typename R, typename A> void foo(E, R (*)(A)); // expected-note 2{{couldn't infer template argument 'R'}}
}
template<typename T> void arg(T);
template<typename T> int arg(T) = delete; // expected-note {{here}} expected-error 0-1{{extension}}
void f(A::E e) {
foo(e, &arg); // expected-error {{no matching function}}
using A::foo;
foo<int, int>(e, &arg); // expected-error {{deleted}}
}
int arg(int);
void g(A::E e) {
foo(e, &arg); // expected-error {{no matching function}}
using A::foo;
foo<int, int>(e, &arg); // ok, uses non-template
}
}
namespace contexts {
template<int I> void f1(int (&)[I]);
template<int I> void f2(int (&)[I+1]); // expected-note {{couldn't infer}}
template<int I> void f3(int (&)[I+1], int (&)[I]);
void f() {
int a[4];
int b[3];
f1(a);
f2(a); // expected-error {{no matching function}}
f3(a, b);
}
template<int I> struct S {};
template<int I> void g1(S<I>);
template<int I> void g2(S<I+1>); // expected-note {{couldn't infer}}
template<int I> void g3(S<I+1>, S<I>);
void g() {
S<4> a;
S<3> b;
g1(a);
g2(a); // expected-error {{no matching function}}
g3(a, b);
}
template<typename T> void h1(T = 0); // expected-note {{couldn't infer}}
template<typename T> void h2(T, T = 0);
void h() {
h1(); // expected-error {{no matching function}}
h1(0);
h1<int>();
h2(0);
}
template<typename T> int tmpl(T);
template<typename R, typename A> void i1(R (*)(A)); // expected-note 3{{couldn't infer}}
template<typename R, typename A> void i2(R, A, R (*)(A)); // expected-note {{not viable}}
void i() {
extern int single(int);
i1(single);
i2(0, 0, single);
extern int ambig(float), ambig(int);
i1(ambig); // expected-error {{no matching function}}
i2(0, 0, ambig);
extern void no_match(float), no_match(int);
i1(no_match); // expected-error {{no matching function}}
i2(0, 0, no_match); // expected-error {{no matching function}}
i1(tmpl); // expected-error {{no matching function}}
i2(0, 0, tmpl);
}
}
template<typename T> struct is_int;
template<> struct is_int<int> {};
namespace example2 {
template<typename T> int f(T (*p)(T)) { is_int<T>(); }
int g(int);
int g(char);
int i = f(g);
}
namespace example3 {
template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
int g(int);
char g(char);
int i = f(1, g);
}
namespace example4 {
template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
char g(char);
template <class T> T g(T);
int i = f(1, g);
}
namespace example5 {
template<int I> class A {};
template<int I> void g(A<I+1>); // expected-note {{couldn't infer}}
template<int I> void f(A<I>, A<I+1>);
void h(A<1> a1, A<2> a2) {
g(a1); // expected-error {{no matching function}}
g<0>(a1);
f(a1, a2);
}
}
}
// dr353 needs an IRGen test.
namespace dr354 { // dr354: yes c++11
// FIXME: Should we allow this in C++98 too?
struct S {};
template<int*> struct ptr {}; // expected-note 0-4{{here}}
ptr<0> p0;
ptr<(int*)0> p1;
ptr<(float*)0> p2;
ptr<(int S::*)0> p3;
#if __cplusplus < 201103L
// expected-error@-5 {{does not refer to any decl}}
// expected-error@-5 {{does not refer to any decl}}
// expected-error@-5 {{does not refer to any decl}}
// expected-error@-5 {{does not refer to any decl}}
#elif __cplusplus <= 201402L
// expected-error@-10 {{must be cast}}
// ok
// expected-error@-10 {{does not match}}
// expected-error@-10 {{does not match}}
#else
// expected-error@-15 {{conversion from 'int' to 'int *' is not allowed}}
// ok
// expected-error@-15 {{'float *' is not implicitly convertible to 'int *'}}
// expected-error@-15 {{'int dr354::S::*' is not implicitly convertible to 'int *'}}
#endif
template<int*> int both();
template<int> int both();
int b0 = both<0>();
int b1 = both<(int*)0>();
#if __cplusplus < 201103L
// expected-error@-2 {{no matching function}}
// expected-note@-6 {{candidate}}
// expected-note@-6 {{candidate}}
#endif
template<int S::*> struct ptr_mem {}; // expected-note 0-4{{here}}
ptr_mem<0> m0;
ptr_mem<(int S::*)0> m1;
ptr_mem<(float S::*)0> m2;
ptr_mem<(int *)0> m3;
#if __cplusplus < 201103L
// expected-error@-5 {{cannot be converted}}
// expected-error@-5 {{is not a pointer to member constant}}
// expected-error@-5 {{cannot be converted}}
// expected-error@-5 {{cannot be converted}}
#elif __cplusplus <= 201402L
// expected-error@-10 {{must be cast}}
// ok
// expected-error@-10 {{does not match}}
// expected-error@-10 {{does not match}}
#else
// expected-error@-15 {{conversion from 'int' to 'int dr354::S::*' is not allowed}}
// ok
// expected-error@-15 {{'float dr354::S::*' is not implicitly convertible to 'int dr354::S::*'}}
// expected-error@-15 {{'int *' is not implicitly convertible to 'int dr354::S::*'}}
#endif
}
struct dr355_S; // dr355: yes
struct ::dr355_S {}; // expected-warning {{extra qualification}}
namespace dr355 { struct ::dr355_S s; }
// dr356: na
namespace dr357 { // dr357: yes
template<typename T> struct A {
void f() const; // expected-note {{const qualified}}
};
template<typename T> void A<T>::f() {} // expected-error {{does not match}}
struct B {
template<typename T> void f();
};
template<typename T> void B::f() const {} // expected-error {{does not match}}
}
namespace dr358 { // dr358: yes
extern "C" void dr358_f();
namespace N {
int var;
extern "C" void dr358_f() { var = 10; }
}
}
namespace dr359 { // dr359: yes
// Note, the example in the DR is wrong; it doesn't contain an anonymous
// union.
struct E {
union {
struct {
int x;
} s;
} v;
union {
struct { // expected-error {{extension}}
int x;
} s;
struct S { // expected-error {{types cannot be declared in an anonymous union}}
int x;
} t;
union { // expected-error {{extension}}
int u;
};
};
};
}
namespace dr360 { // dr360: yes
struct A {
int foo();
int bar();
protected:
int baz();
};
struct B : A {
private:
using A::foo; // #dr360-foo-using-decl
protected:
using A::bar; // #dr360-bar-using-decl
public:
using A::baz; // #dr360-baz-using-decl
};
int main() {
int foo = B().foo(); // expected-error {{is a private member}}
// expected-note@#dr360-foo-using-decl {{declared private here}}
int bar = B().bar(); // expected-error {{is a protected member}}
// expected-note@#dr360-bar-using-decl {{declared protected here}}
int baz = B().baz();
}
} // namespace dr360
// dr362: na
// dr363: na
namespace dr364 { // dr364: yes
struct S {
static void f(int);
void f(char);
};
void g() {
S::f('a'); // expected-error {{call to non-static}}
S::f(0);
}
}
#if "foo" // expected-error {{invalid token}} dr366: yes
#endif
namespace dr367 { // dr367: yes
// FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
// array as being a VLA!
int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
int b[true ? 4 : throw 0];
int c[true ? *new int : 4]; // expected-error 2{{variable length array}} expected-note {{read of uninitialized}}
int d[true ? 4 : *new int];
#if __cplusplus < 201103L
// expected-error@-4 2{{variable length array}}
// expected-error@-3 2{{variable length array}}
#endif
}
namespace dr368 { // dr368: yes
template<typename T, T> struct S {}; // expected-note {{here}}
template<typename T> int f(S<T, T()> *); // expected-error {{function type}}
template<typename T> int g(S<T, (T())> *); // cxx98_17-note {{type 'X'}}
// cxx20_2b-note@-1 {{candidate function [with T = dr368::X]}}
template<typename T> int g(S<T, true ? T() : T()> *); // cxx98_17-note {{type 'X'}}
// cxx20_2b-note@-1 {{candidate function [with T = dr368::X]}}
struct X {};
int n = g<X>(0); // cxx98_17-error {{no matching}}
// cxx20_2b-error@-1 {{call to 'g' is ambiguous}}
}
// dr370: na
namespace dr372 { // dr372: no
namespace example1 {
template<typename T> struct X {
protected:
typedef T Type; // expected-note 2{{protected}}
};
template<typename T> struct Y {};
// FIXME: These two are valid; deriving from T1<T> gives Z1 access to
// the protected member T1<T>::Type.
template<typename T,
template<typename> class T1,
template<typename> class T2> struct Z1 :
T1<T>,
T2<typename T1<T>::Type> {}; // expected-error {{protected}}
template<typename T,
template<typename> class T1,
template<typename> class T2> struct Z2 :
T2<typename T1<T>::Type>, // expected-error {{protected}}
T1<T> {};
Z1<int, X, Y> z1; // expected-note {{instantiation of}}
Z2<int, X, Y> z2; // expected-note {{instantiation of}}
}
namespace example2 {
struct X {
private:
typedef int Type; // expected-note {{private}}
};
template<typename T> struct A {
typename T::Type t; // expected-error {{private}}
};
A<X> ax; // expected-note {{instantiation of}}
}