]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CXX/drs/dr16xx.cpp
Vendor import of clang trunk r300422:
[FreeBSD/FreeBSD.git] / test / CXX / drs / dr16xx.cpp
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5
6 namespace dr1611 { // dr1611: dup 1658
7   struct A { A(int); };
8   struct B : virtual A { virtual void f() = 0; };
9   struct C : B { C() : A(0) {} void f(); };
10   C c;
11 }
12
13 namespace dr1684 { // dr1684: 3.6
14 #if __cplusplus >= 201103L
15   struct NonLiteral { // expected-note {{because}}
16     NonLiteral();
17     constexpr int f() { return 0; } // expected-warning 0-1{{will not be implicitly 'const'}}
18   };
19   constexpr int f(NonLiteral &) { return 0; }
20   constexpr int f(NonLiteral) { return 0; } // expected-error {{not a literal type}}
21 #endif
22 }
23
24 namespace dr1631 {  // dr1631: 3.7
25 #if __cplusplus >= 201103L
26   // Incorrect overload resolution for single-element initializer-list
27
28   struct A { int a[1]; };
29   struct B { B(int); };
30   void f(B, int);
31   void f(B, int, int = 0);
32   void f(int, A);
33
34   void test() {
35     f({0}, {{1}}); // expected-warning {{braces around scalar init}}
36   }
37
38   namespace with_error {
39     void f(B, int);           // TODO: expected- note {{candidate function}}
40     void f(int, A);           // expected-note {{candidate function}}
41     void f(int, A, int = 0);  // expected-note {{candidate function}}
42     
43     void test() {
44       f({0}, {{1}});        // expected-error{{call to 'f' is ambiguous}}
45     }
46   }
47 #endif
48 }
49
50 namespace dr1638 { // dr1638: yes
51 #if __cplusplus >= 201103L
52   template<typename T> struct A {
53     enum class E; // expected-note {{previous}}
54     enum class F : T; // expected-note 2{{previous}}
55   };
56
57   template<> enum class A<int>::E;
58   template<> enum class A<int>::E {};
59   template<> enum class A<int>::F : int;
60   template<> enum class A<int>::F : int {};
61
62   template<> enum class A<short>::E : int;
63   template<> enum class A<short>::E : int {};
64
65   template<> enum class A<short>::F; // expected-error {{different underlying type}}
66   template<> enum class A<char>::E : char; // expected-error {{different underlying type}}
67   template<> enum class A<char>::F : int; // expected-error {{different underlying type}}
68
69   enum class A<unsigned>::E; // expected-error {{template specialization requires 'template<>'}} expected-error {{nested name specifier}}
70   template enum class A<unsigned>::E; // expected-error {{enumerations cannot be explicitly instantiated}}
71   enum class A<unsigned>::E *e; // expected-error {{must use 'enum' not 'enum class'}}
72
73   struct B {
74     friend enum class A<unsigned>::E; // expected-error {{must use 'enum' not 'enum class'}}
75   };
76 #endif
77 }
78
79 namespace dr1645 { // dr1645: 3.9
80 #if __cplusplus >= 201103L
81   struct A {
82     constexpr A(int, float = 0); // expected-note 2{{candidate}}
83     explicit A(int, int = 0); // expected-note 2{{candidate}}
84     A(int, int, int = 0) = delete; // expected-note {{candidate}}
85   };
86
87   struct B : A { // expected-note 2{{candidate}}
88     using A::A; // expected-note 5{{inherited here}}
89   };
90
91   constexpr B a(0); // expected-error {{ambiguous}}
92   constexpr B b(0, 0); // expected-error {{ambiguous}}
93 #endif
94 }
95
96 namespace dr1653 { // dr1653: 4 c++17
97   void f(bool b) {
98     ++b;
99     b++;
100 #if __cplusplus <= 201402L
101     // expected-warning@-3 {{deprecated}} expected-warning@-2 {{deprecated}}
102 #else
103     // expected-error@-5 {{incrementing expression of type bool}} expected-error@-4 {{incrementing expression of type bool}}
104 #endif
105     --b; // expected-error {{cannot decrement expression of type bool}}
106     b--; // expected-error {{cannot decrement expression of type bool}}
107     b += 1; // ok
108     b -= 1; // ok
109   }
110 }
111
112 namespace dr1658 { // dr1658: 5
113   namespace DefCtor {
114     class A { A(); }; // expected-note 0-2{{here}}
115     class B { ~B(); }; // expected-note 0-2{{here}}
116
117     // The stars align! An abstract class does not construct its virtual bases.
118     struct C : virtual A { C(); virtual void foo() = 0; };
119     C::C() = default; // ok, not deleted, expected-error 0-1{{extension}}
120     struct D : virtual B { D(); virtual void foo() = 0; };
121     D::D() = default; // ok, not deleted, expected-error 0-1{{extension}}
122
123     // In all other cases, we are not so lucky.
124     struct E : A { E(); virtual void foo() = 0; };
125 #if __cplusplus < 201103L
126     E::E() = default; // expected-error {{private default constructor}} expected-error {{extension}} expected-note {{here}}
127 #else
128     E::E() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible default constructor}}
129 #endif
130     struct F : virtual A { F(); };
131 #if __cplusplus < 201103L
132     F::F() = default; // expected-error {{private default constructor}} expected-error {{extension}} expected-note {{here}}
133 #else
134     F::F() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible default constructor}}
135 #endif
136
137     struct G : B { G(); virtual void foo() = 0; };
138 #if __cplusplus < 201103L
139     G::G() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
140 #else
141     G::G() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
142 #endif
143     struct H : virtual B { H(); };
144 #if __cplusplus < 201103L
145     H::H() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
146 #else
147     H::H() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
148 #endif
149   }
150
151   namespace Dtor {
152     class B { ~B(); }; // expected-note 0-2{{here}}
153
154     struct D : virtual B { ~D(); virtual void foo() = 0; };
155     D::~D() = default; // ok, not deleted, expected-error 0-1{{extension}}
156
157     struct G : B { ~G(); virtual void foo() = 0; };
158 #if __cplusplus < 201103L
159     G::~G() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
160 #else
161     G::~G() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
162 #endif
163     struct H : virtual B { ~H(); };
164 #if __cplusplus < 201103L
165     H::~H() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
166 #else
167     H::~H() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
168 #endif
169   }
170
171   namespace MemInit {
172     struct A { A(int); }; // expected-note {{here}}
173     struct B : virtual A {
174       B() {}
175       virtual void f() = 0;
176     };
177     struct C : virtual A {
178       C() {} // expected-error {{must explicitly initialize}}
179     };
180   }
181
182   namespace CopyCtorParamType {
183     struct A { A(A&); };
184     struct B : virtual A { virtual void f() = 0; };
185     struct C : virtual A { virtual void f(); };
186     struct D : A { virtual void f() = 0; };
187
188     struct X {
189       friend B::B(const B&) throw();
190       friend C::C(C&);
191       friend D::D(D&);
192     };
193   }
194
195   namespace CopyCtor {
196     class A { A(const A&); A(A&&); }; // expected-note 0-4{{here}} expected-error 0-1{{extension}}
197
198     struct C : virtual A { C(const C&); C(C&&); virtual void foo() = 0; }; // expected-error 0-1{{extension}}
199     C::C(const C&) = default; // expected-error 0-1{{extension}}
200     C::C(C&&) = default; // expected-error 0-2{{extension}}
201
202     struct E : A { E(const E&); E(E&&); virtual void foo() = 0; }; // expected-error 0-1{{extension}}
203 #if __cplusplus < 201103L
204     E::E(const E&) = default; // expected-error {{private copy constructor}} expected-error {{extension}} expected-note {{here}}
205     E::E(E&&) = default; // expected-error {{private move constructor}} expected-error 2{{extension}} expected-note {{here}}
206 #else
207     E::E(const E&) = default; // expected-error {{would delete}} expected-note@-5{{inaccessible copy constructor}}
208     E::E(E&&) = default; // expected-error {{would delete}} expected-note@-6{{inaccessible move constructor}}
209 #endif
210     struct F : virtual A { F(const F&); F(F&&); }; // expected-error 0-1{{extension}}
211 #if __cplusplus < 201103L
212     F::F(const F&) = default; // expected-error {{private copy constructor}} expected-error {{extension}} expected-note {{here}}
213     F::F(F&&) = default; // expected-error {{private move constructor}} expected-error 2{{extension}} expected-note {{here}}
214 #else
215     F::F(const F&) = default; // expected-error {{would delete}} expected-note@-5{{inaccessible copy constructor}}
216     F::F(F&&) = default; // expected-error {{would delete}} expected-note@-6{{inaccessible move constructor}}
217 #endif
218   }
219
220   // assignment case is superseded by dr2180
221 }