Clang Project

clang_source_code/test/CXX/drs/dr19xx.cpp
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
5
6namespace std { struct type_info; }
7
8namespace dr1902 { // dr1902: 3.7
9  struct A {};
10  struct B {
11    B(A);
12#if __cplusplus >= 201103L
13        // expected-note@-2 {{candidate}}
14#endif
15
16    B() = delete;
17#if __cplusplus < 201103L
18        // expected-error@-2 {{extension}}
19#endif
20
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;
28
29    operator A();
30  };
31
32  extern B b1;
33  B b2(b1); // expected-error {{call to deleted}}
34
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
40}
41
42namespace dr1903 {
43  namespace A {
44    struct a {};
45    int a;
46    namespace B {
47      int b;
48    }
49    using namespace B;
50    namespace {
51      int c;
52    }
53    namespace D {
54      int d;
55    }
56    using D::d;
57  }
58  namespace X {
59    using A::a;
60    using A::b;
61    using A::c;
62    using A::d;
63    struct a *p;
64  }
65}
66
67namespace dr1909 { // dr1909: yes
68  struct A {
69    template<typename T> struct A {}; // expected-error {{member 'A' has the same name as its class}}
70  };
71  struct B {
72    template<typename T> void B() {} // expected-error {{constructor cannot have a return type}}
73  };
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}}
76  };
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}}
79  };
80}
81
82namespace dr1940 { // dr1940: yes
83#if __cplusplus >= 201103L
84static union {
85  static_assert(true, "");  // ok
86  static_assert(false, ""); // expected-error {{static_assert failed}}
87};
88#endif
89}
90
91namespace dr1941 { // dr1941: 3.9
92#if __cplusplus >= 201402L
93template<typename X>
94struct base {
95  template<typename T>
96  base(T a, T b, decltype(void(*T()), 0) = 0) {
97    while (a != b) (void)*a++;
98  }
99
100  template<typename T>
101  base(T a, X x, decltype(void(T(0) * 1), 0) = 0) {
102    for (T n = 0; n != a; ++n) (void)X(x);
103  }
104};
105
106struct derived : base<int> {
107  using base::base;
108};
109
110struct iter {
111  iter operator++(int);
112  int operator*();
113  friend bool operator!=(iter, iter);
114} it, end;
115
116derived d1(it, end);
117derived d2(42, 9);
118#endif
119}
120
121namespace dr1947 { // dr1947: yes
122#if __cplusplus >= 201402L
123unsigned o = 0'01;  // ok
124unsigned b = 0b'01; // expected-error {{invalid digit 'b' in octal constant}}
125unsigned x = 0x'01; // expected-error {{invalid suffix 'x'01' on integer constant}}
126#endif
127}
128
129#if __cplusplus >= 201103L
130// dr1948: yes
131// FIXME: This diagnostic could be improved.
132void *operator new(__SIZE_TYPE__) noexcept { return nullptr; } // expected-error{{exception specification in declaration does not match previous declaration}}
133#endif
134
135namespace dr1959 { // dr1959: 3.9
136#if __cplusplus >= 201103L
137  struct b;
138  struct c;
139  struct a {
140    a() = default;
141    a(const a &) = delete; // expected-note {{deleted}}
142    a(const b &) = delete; // not inherited
143    a(c &&) = delete; // expected-note {{not viable}}
144    template<typename T> a(T) = delete; // expected-note {{would take its own class type by value}}
145  };
146
147  struct b : a { // expected-note {{cannot bind}} expected-note {{deleted because}}
148    using a::a; // expected-note 2{{inherited here}}
149  };
150
151  a x;
152  // FIXME: As a resolution to an open DR against P0136R0, we disallow
153  // use of inherited constructors to construct from a single argument
154  // where the base class is reference-related to the argument type.
155  b y = x; // expected-error {{no viable conversion}}
156  b z = z; // expected-error {{deleted}}
157
158  struct c : a {
159    using a::a;
160    c(const c &);
161  };
162  // FIXME: As a resolution to an open DR against P0136R0, we disallow
163  // use of inherited constructors to construct from a single argument
164  // where the base class is reference-related to the argument type.
165  c q(static_cast<c&&>(q));
166#endif
167}
168
169namespace dr1968 { // dr1968: yes
170#if __cplusplus >= 201103L
171  static_assert(&typeid(int) == &typeid(int), ""); // expected-error{{not an integral constant expression}}
172#endif
173}
174
175namespace dr1991 { // dr1991: 3.9
176#if __cplusplus >= 201103L
177  struct A {
178    A(int, int) = delete;
179  };
180
181  struct B : A {
182    using A::A;
183    B(int, int, int = 0);
184  };
185
186  // FIXME: As a resolution to an open DR against P0136R1, we treat derived
187  // class constructors as better than base class constructors in the presence
188  // of ambiguity.
189  B b(0, 0); // ok, calls B constructor
190#endif
191}
192
193// dr1994: dup 529
194