1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-11,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx98-11,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
9 namespace std
{ struct type_info
; }
11 namespace cwg1900
{ // cwg1900: 2.7
12 // See the test for CWG1477 for detailed analysis
18 int N::f() { return 0; }
19 int N::g() { return 0; }
20 // expected-error@-1 {{out-of-line definition of 'g' does not match any declaration in namespace 'cwg1900::N'}}
21 } // namespace cwg1900
23 namespace cwg1902
{ // cwg1902: 3.7
27 B() = delete; // #cwg1902-B-ctor
28 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
29 B(const B
&) = delete; // #cwg1902-B-copy-ctor
30 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
36 // expected-error@-1 {{call to deleted constructor of 'B'}}
37 // expected-note@#cwg1902-B-copy-ctor {{'B' has been explicitly marked deleted here}}
39 #if __cplusplus >= 201103L
40 // This is ambiguous, even though calling the B(const B&) constructor would
41 // both directly and indirectly call a deleted function.
43 // since-cxx11-error@-1 {{call to constructor of 'B' is ambiguous}}
44 // since-cxx11-note@#cwg1902-B-A {{candidate constructor}}
45 // since-cxx11-note@#cwg1902-B-copy-ctor {{candidate constructor has been explicitly deleted}}
49 namespace cwg1903
{ // cwg1903: 2.7
74 namespace cwg1909
{ // cwg1909: 3.7
76 template<typename T
> struct A
{};
77 // expected-error@-1 {{member 'A' has the same name as its class}}
80 template<typename T
> void B() {}
81 // expected-error@-1 {{constructor cannot have a return type}}
84 template<typename T
> static int C
;
85 // expected-error@-1 {{member 'C' has the same name as its class}}
86 // cxx98-11-error@-2 {{variable templates are a C++14 extension}}
89 template<typename T
> using D
= int;
90 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
91 // expected-error@-2 {{member 'D' has the same name as its class}}
95 namespace cwg1918
{ // cwg1918: no
96 template<typename T
> struct A
{
103 // FIXME: this is ill-formed, because A<T>::B::C does not end with a simple-template-id
104 template <typename T
>
105 friend class A
<T
>::B::C
;
106 // expected-warning@-1 {{dependent nested name specifier 'A<T>::B::' for friend class declaration is not supported; turning off access control for 'X'}}
108 template<> struct A
<int> {
113 // FIXME: 'f' is not a friend, so 'X::x' is not accessible
114 int f() { return X::x
; }
117 } // namespace cwg1918
119 namespace cwg1940
{ // cwg1940: 3.5
120 #if __cplusplus >= 201103L
122 static_assert(true, ""); // ok
123 static_assert(false, "");
124 // since-cxx11-error@-1 {{static assertion failed}}
130 namespace cwg1941
{ // cwg1941: 3.9
131 #if __cplusplus >= 201402L
135 base(T a
, T b
, decltype(void(*T()), 0) = 0) {
136 while (a
!= b
) (void)*a
++;
140 base(T a
, X x
, decltype(void(T(0) * 1), 0) = 0) {
141 for (T n
= 0; n
!= a
; ++n
) (void)X(x
);
145 struct derived
: base
<int> {
150 iter
operator++(int);
152 friend bool operator!=(iter
, iter
);
160 namespace cwg1945
{ // cwg1945: no
161 template<typename T
> struct A
{
168 // FIXME: this is ill-formed, because A<T>::B::C does not end with a simple-template-id
169 template <typename T
>
170 friend class A
<T
>::B::C
;
171 // expected-warning@-1 {{dependent nested name specifier 'A<T>::B::' for friend class declaration is not supported; turning off access control for 'X'}}
173 } // namespace cwg1945
175 namespace cwg1947
{ // cwg1947: 3.5
176 #if __cplusplus >= 201402L
177 unsigned o
= 0'01; // ok
179 // since-cxx14-error@-1 {{invalid digit 'b' in octal constant}}
181 // since-cxx14-error@-1 {{invalid suffix 'x'01' on integer constant}}
185 #if __cplusplus >= 201103L
187 // FIXME: This diagnostic could be improved.
188 void *operator new(__SIZE_TYPE__
) noexcept
{ return nullptr; }
189 // since-cxx11-error@-1 {{exception specification in declaration does not match previous declaration}}
192 namespace cwg1959
{ // cwg1959: 3.9
193 #if __cplusplus >= 201103L
198 a(const a
&) = delete; // #cwg1959-copy-ctor
199 a(const b
&) = delete; // not inherited
200 a(c
&&) = delete; // #cwg1959-move-ctor
201 template<typename T
> a(T
) = delete; // #cwg1959-temp-ctor
204 struct b
: a
{ // #cwg1959-b
205 using a::a
; // #cwg1959-using-a
209 // FIXME: As a resolution to an open DR against P0136R0, we disallow
210 // use of inherited constructors to construct from a single argument
211 // where the base class is reference-related to the argument type.
213 // since-cxx11-error@-1 {{no viable conversion from 'a' to 'b'}}
214 // since-cxx11-note@#cwg1959-move-ctor {{candidate inherited constructor not viable: no known conversion from 'a' to 'c &&' for 1st argument}}
215 // since-cxx11-note@#cwg1959-using-a {{constructor from base class 'a' inherited here}}
216 // since-cxx11-note@#cwg1959-b {{candidate constructor (the implicit copy constructor) not viable: cannot bind base class object of type 'a' to derived class reference 'const b &' for 1st argument}}
217 // since-cxx11-note@#cwg1959-temp-ctor {{candidate template ignored: instantiation would take its own class type by value}}
218 // since-cxx11-note@#cwg1959-using-a {{constructor from base class 'a' inherited here}}
220 // since-cxx11-error@-1 {{call to implicitly-deleted copy constructor of 'b'}}
221 // since-cxx11-note@#cwg1959-b {{copy constructor of 'b' is implicitly deleted because base class 'a' has a deleted copy constructor}}
222 // since-cxx11-note@#cwg1959-copy-ctor {{'a' has been explicitly marked deleted here}}
228 // FIXME: As a resolution to an open DR against P0136R0, we disallow
229 // use of inherited constructors to construct from a single argument
230 // where the base class is reference-related to the argument type.
231 c
q(static_cast<c
&&>(q
));
235 namespace cwg1960
{ // cwg1960: no
249 // FIXME: both declarations are ill-formed, because A::f and A::g
250 // are not accessible.
256 namespace cwg1966
{ // cwg1966: 11
257 #if __cplusplus >= 201103L
260 // since-cxx11-error@-1 {{expected identifier}} (not bit-field)
262 auto *p1
= new enum E
: int;
263 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
264 auto *p2
= new enum F
: int {};
265 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
266 auto *p3
= true ? new enum G
: int {};
267 // since-cxx11-error@-1 {{ISO C++ forbids forward references to 'enum' types}}
268 // since-cxx11-error@-2 {{allocation of incomplete type 'enum G'}}
269 // since-cxx11-note@-3 {{forward declaration of 'cwg1966::G'}}
270 auto h() -> enum E
: int {};
271 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
273 enum X
: enum Y
: int {} {};
274 // since-cxx11-error@-1 {{'cwg1966::Y' cannot be defined in a type specifier}}
276 // FIXME: can we emit something nicer than that?
277 enum X
: enum Y
: int {} {};
278 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
279 // since-cxx11-error@-2 {{non-integral type 'enum Y' is an invalid underlying type}}
280 // since-cxx11-error@-3 {{anonymous bit-field cannot have a default member initializer}}
285 namespace cwg1968
{ // cwg1968: no
286 #if __cplusplus >= 201103L
287 // FIXME: According to CWG1968, both of these should be considered
289 static_assert(&typeid(int) == &typeid(int), "");
291 constexpr const std::type_info
*f() { return &typeid(int); }
292 static_assert(f() == f(), "");
296 namespace cwg1991
{ // cwg1991: 3.9
297 #if __cplusplus >= 201103L
299 A(int, int) = delete;
304 B(int, int, int = 0);
307 // FIXME: As a resolution to an open DR against P0136R1, we treat derived
308 // class constructors as better than base class constructors in the presence
310 B
b(0, 0); // ok, calls B constructor