Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr19xx.cpp
blobb15be762ecd1099b5b2b1eb7b3a309895a9db7b6
1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 namespace std { struct type_info; }
8 namespace dr1902 { // dr1902: 3.7
9 struct A {};
10 struct B {
11 B(A);
12 #if __cplusplus >= 201103L
13 // expected-note@-2 {{candidate}}
14 #endif
16 B() = delete;
17 #if __cplusplus < 201103L
18 // expected-error@-2 {{extension}}
19 #endif
21 B(const B&) // expected-note {{deleted here}}
22 #if __cplusplus >= 201103L
23 // expected-note@-2 {{candidate}}
24 #else
25 // expected-error@+2 {{extension}}
26 #endif
27 = delete;
29 operator A();
32 extern B b1;
33 B b2(b1); // expected-error {{call to deleted}}
35 #if __cplusplus >= 201103L
36 // This is ambiguous, even though calling the B(const B&) constructor would
37 // both directly and indirectly call a deleted function.
38 B b({}); // expected-error {{ambiguous}}
39 #endif
42 namespace dr1903 {
43 namespace A {
44 struct a {};
45 int a;
46 namespace B {
47 int b;
49 using namespace B;
50 namespace {
51 int c;
53 namespace D {
54 int d;
56 using D::d;
58 namespace X {
59 using A::a;
60 using A::b;
61 using A::c;
62 using A::d;
63 struct a *p;
67 namespace dr1909 { // dr1909: yes
68 struct A {
69 template<typename T> struct A {}; // expected-error {{member 'A' has the same name as its class}}
71 struct B {
72 template<typename T> void B() {} // expected-error {{constructor cannot have a return type}}
74 struct C {
75 template<typename T> static int C; // expected-error {{member 'C' has the same name as its class}} expected-error 0-1{{extension}}
77 struct D {
78 template<typename T> using D = int; // expected-error {{member 'D' has the same name as its class}} expected-error 0-1{{extension}}
82 namespace dr1940 { // dr1940: yes
83 #if __cplusplus >= 201103L
84 static union {
85 static_assert(true, ""); // ok
86 static_assert(false, ""); // expected-error {{static assertion failed}}
87 int not_empty;
89 #endif
92 namespace dr1941 { // dr1941: 3.9
93 #if __cplusplus >= 201402L
94 template<typename X>
95 struct base {
96 template<typename T>
97 base(T a, T b, decltype(void(*T()), 0) = 0) {
98 while (a != b) (void)*a++;
101 template<typename T>
102 base(T a, X x, decltype(void(T(0) * 1), 0) = 0) {
103 for (T n = 0; n != a; ++n) (void)X(x);
107 struct derived : base<int> {
108 using base::base;
111 struct iter {
112 iter operator++(int);
113 int operator*();
114 friend bool operator!=(iter, iter);
115 } it, end;
117 derived d1(it, end);
118 derived d2(42, 9);
119 #endif
122 namespace dr1947 { // dr1947: yes
123 #if __cplusplus >= 201402L
124 unsigned o = 0'01; // ok
125 unsigned b = 0b'01; // expected-error {{invalid digit 'b' in octal constant}}
126 unsigned x = 0x'01; // expected-error {{invalid suffix 'x'01' on integer constant}}
127 #endif
130 #if __cplusplus >= 201103L
131 // dr1948: yes
132 // FIXME: This diagnostic could be improved.
133 void *operator new(__SIZE_TYPE__) noexcept { return nullptr; } // expected-error{{exception specification in declaration does not match previous declaration}}
134 #endif
136 namespace dr1959 { // dr1959: 3.9
137 #if __cplusplus >= 201103L
138 struct b;
139 struct c;
140 struct a {
141 a() = default;
142 a(const a &) = delete; // expected-note {{deleted}}
143 a(const b &) = delete; // not inherited
144 a(c &&) = delete; // expected-note {{not viable}}
145 template<typename T> a(T) = delete; // expected-note {{would take its own class type by value}}
148 struct b : a { // expected-note {{cannot bind}} expected-note {{deleted because}}
149 using a::a; // expected-note 2{{inherited here}}
152 a x;
153 // FIXME: As a resolution to an open DR against P0136R0, we disallow
154 // use of inherited constructors to construct from a single argument
155 // where the base class is reference-related to the argument type.
156 b y = x; // expected-error {{no viable conversion}}
157 b z = z; // expected-error {{deleted}}
159 struct c : a {
160 using a::a;
161 c(const c &);
163 // FIXME: As a resolution to an open DR against P0136R0, we disallow
164 // use of inherited constructors to construct from a single argument
165 // where the base class is reference-related to the argument type.
166 c q(static_cast<c&&>(q));
167 #endif
170 namespace dr1960 { // dr1960: no
171 struct A {
172 void f() {}
173 protected:
174 void g() {}
177 struct B: A {
178 private:
179 using A::f;
180 using A::g;
183 struct C : B {
184 // FIXME: both declarations are ill-formed, because A::f and A::g
185 // are not accessible.
186 using A::f;
187 using A::g;
191 namespace dr1966 { // dr1966: 11
192 #if __cplusplus >= 201103L
193 struct A {
194 enum E : int {1}; // expected-error {{expected identifier}} (not bit-field)
196 auto *p1 = new enum E : int; // expected-error {{only permitted as a standalone declaration}}
197 auto *p2 = new enum F : int {}; // expected-error {{only permitted as a standalone declaration}}
198 auto *p3 = true ? new enum G : int {}; // expected-error {{forward reference}} expected-error {{incomplete}} expected-note {{declaration}}
199 auto h() -> enum E : int {}; // expected-error {{only permitted as a standalone declaration}}
201 enum X : enum Y : int {} {}; // expected-error {{cannot be defined in a type specifier}}
202 struct Q {
203 enum X : enum Y : int {} {}; // expected-error +{{}}
205 #endif
208 namespace dr1968 { // dr1968: no
209 #if __cplusplus >= 201103L
210 // FIXME: According to DR1968, both of these should be considered
211 // non-constant.
212 static_assert(&typeid(int) == &typeid(int), "");
214 constexpr const std::type_info *f() { return &typeid(int); }
215 static_assert(f() == f(), "");
216 #endif
219 namespace dr1991 { // dr1991: 3.9
220 #if __cplusplus >= 201103L
221 struct A {
222 A(int, int) = delete;
225 struct B : A {
226 using A::A;
227 B(int, int, int = 0);
230 // FIXME: As a resolution to an open DR against P0136R1, we treat derived
231 // class constructors as better than base class constructors in the presence
232 // of ambiguity.
233 B b(0, 0); // ok, calls B constructor
234 #endif
237 // dr1994: dup 529