1 // RUN: %clang_cc1 -std=c++98 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
2 // RUN: %clang_cc1 -std=c++98 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
3 // RUN: %clang_cc1 -std=c++11 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
4 // RUN: %clang_cc1 -std=c++11 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
5 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
6 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
7 // RUN: %clang_cc1 -std=c++17 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu
8 // RUN: %clang_cc1 -std=c++17 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -fms-compatibility
9 // RUN: %clang_cc1 -std=c++2a %s -Wno-parentheses -Wdeprecated -verify=expected,cxx20 -triple x86_64-linux-gnu
10 // RUN: %clang_cc1 -std=c++2a %s -Wno-parentheses -Wdeprecated -verify=expected,cxx20 -triple x86_64-linux-gnu -fms-compatibility
12 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -Wno-deprecated-register -DNO_DEPRECATED_FLAGS
13 // RUN: %clang_cc1 -std=c++14 %s -Wno-parentheses -Wdeprecated -verify=expected,not-cxx20 -triple x86_64-linux-gnu -Wno-deprecated-register -DNO_DEPRECATED_FLAGS -fms-compatibility
15 #include "Inputs/register.h"
24 #if __cplusplus > 201402L
25 // expected-warning@-4 {{dynamic exception specifications are deprecated}} expected-note@-4 {{use 'noexcept' instead}}
26 // expected-error@-4 {{ISO C++17 does not allow dynamic exception specifications}} expected-note@-4 {{use 'noexcept(false)' instead}}
27 // expected-error@-4 {{ISO C++17 does not allow dynamic exception specifications}} expected-note@-4 {{use 'noexcept(false)' instead}}
28 #elif __cplusplus >= 201103L
29 // expected-warning@-8 {{dynamic exception specifications are deprecated}} expected-note@-8 {{use 'noexcept' instead}}
30 // expected-warning@-8 {{dynamic exception specifications are deprecated}} expected-note@-8 {{use 'noexcept(false)' instead}}
31 // expected-warning@-8 {{dynamic exception specifications are deprecated}} expected-note@-8 {{use 'noexcept(false)' instead}}
34 void stuff(register int q
) {
35 #if __cplusplus > 201402L
36 // expected-error@-2 {{ISO C++17 does not allow 'register' storage class specifier}}
37 #elif __cplusplus >= 201103L && !defined(NO_DEPRECATED_FLAGS)
38 // expected-warning@-4 {{'register' storage class specifier is deprecated}}
41 #if __cplusplus > 201402L
42 // expected-error@-2 {{ISO C++17 does not allow 'register' storage class specifier}}
43 #elif __cplusplus >= 201103L && !defined(NO_DEPRECATED_FLAGS)
44 // expected-warning@-4 {{'register' storage class specifier is deprecated}}
47 register int m
asm("rbx"); // no-warning
49 int k
= to_int(n
); // no-warning
52 #if __cplusplus > 201402L
53 // expected-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
55 // expected-warning@-4 {{incrementing expression of type bool is deprecated}}
59 #if __cplusplus > 201402L
60 // expected-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
62 // expected-warning@-4 {{incrementing expression of type bool is deprecated}}
66 #if __cplusplus < 201103L
67 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
69 // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}}
73 struct S
{ int n
; void operator+(int); };
74 struct T
: private S
{
76 #if __cplusplus < 201103L
77 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
79 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
82 #if __cplusplus < 201103L
83 // expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
85 // expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
89 #if __cplusplus >= 201103L
90 namespace DeprecatedCopy
{
92 Assign
&operator=(const Assign
&); // expected-warning {{definition of implicit copy constructor for 'Assign' is deprecated because it has a user-provided copy assignment operator}}
94 Assign a1
, a2(a1
); // expected-note {{implicit copy constructor for 'DeprecatedCopy::Assign' first required here}}
98 Ctor(const Ctor
&); // expected-warning {{definition of implicit copy assignment operator for 'Ctor' is deprecated because it has a user-provided copy constructor}}
101 void f() { b1
= b2
; } // expected-note {{implicit copy assignment operator for 'DeprecatedCopy::Ctor' first required here}}
105 // expected-warning@-1 {{definition of implicit copy constructor for 'Dtor' is deprecated because it has a user-provided destructor}}
106 // expected-warning@-2 {{definition of implicit copy assignment operator for 'Dtor' is deprecated because it has a user-provided destructor}}
108 Dtor c1
, c2(c1
); // expected-note {{implicit copy constructor for 'DeprecatedCopy::Dtor' first required here}}
109 void g() { c1
= c2
; } // expected-note {{implicit copy assignment operator for 'DeprecatedCopy::Dtor' first required here}}
111 struct DefaultedDtor
{
112 ~DefaultedDtor() = default; // expected-warning {{definition of implicit copy constructor for 'DefaultedDtor' is deprecated because it has a user-declared destructor}}
113 }; // expected-warning@-1 {{definition of implicit copy assignment operator for 'DefaultedDtor' is deprecated because it has a user-declared destructor}}
115 DefaultedDtor
d2(d1
); // expected-note {{in implicit copy constructor for 'DeprecatedCopy::DefaultedDtor' first required here}}
116 void h() { d1
= d2
; } // expected-note {{in implicit copy assignment operator for 'DeprecatedCopy::DefaultedDtor' first required here}}
121 friend int operator,(X
, X
);
122 void operator[](int);
124 void array_index_comma() {
126 (void)arr
[(void)1, 2];
130 #if __cplusplus > 201703L
131 // expected-warning@-5 {{deprecated}}
132 // expected-warning@-5 {{deprecated}}
133 // expected-warning@-5 {{deprecated}}
134 // expected-warning@-5 {{deprecated}}
137 (void)arr
[((void)1, 2)];
138 (void)arr
[(X(), X())];
139 (void)((void)1,2)[arr
];
140 (void)(X(), X())[arr
];
145 namespace DeprecatedVolatile
{
149 // simple assignments are deprecated only if their value is used
151 #if __cplusplus >= 201103L
152 decltype(n
= 5) m
= n
; // ok expected-warning {{side effects}}
153 (void)noexcept(n
= 5); // ok expected-warning {{side effects}}
155 (void)typeid(n
= 5); // ok expected-warning {{side effects}}
157 use(n
= 5); // cxx20-warning {{use of result of assignment to object of volatile-qualified type 'volatile int' is deprecated}}
158 int q
= n
= 5; // cxx20-warning {{deprecated}}
159 q
= n
= 5; // cxx20-warning {{deprecated}}
160 #if __cplusplus >= 201103L
161 decltype(q
= n
= 5) m2
= q
; // cxx20-warning {{deprecated}} expected-warning {{side effects}}
162 (void)noexcept(q
= n
= 5); // cxx20-warning {{deprecated}} expected-warning {{side effects}}
164 (void)sizeof(q
= n
= 5); // cxx20-warning {{deprecated}} expected-warning {{side effects}}
165 (void)typeid(use(n
= 5)); // cxx20-warning {{deprecated}} expected-warning {{side effects}}
166 (void)__alignof(+(n
= 5)); // cxx20-warning {{deprecated}} expected-warning {{side effects}}
168 // FIXME: These cases are technically deprecated because the parens are
169 // part of the operand, but we choose to not diagnose for now.
170 (void)sizeof(n
= 5); // expected-warning {{side effects}}
171 (void)__alignof(n
= 5); // expected-warning {{side effects}}
175 volatile bool b
= true;
176 if (b
= true) {} // cxx20-warning {{deprecated}}
178 b
= true; // cxx20-warning {{deprecated}}
180 for (volatile bool x
= true;
181 volatile bool y
= true; // ok despite volatile load from volatile initialization
184 // inc / dec / compound assignments are always deprecated
185 ++n
; // cxx20-warning {{increment of object of volatile-qualified type 'volatile int' is deprecated}}
186 --n
; // cxx20-warning {{decrement of object of volatile-qualified type 'volatile int' is deprecated}}
187 n
++; // cxx20-warning {{increment of object of volatile-qualified type 'volatile int' is deprecated}}
188 n
--; // cxx20-warning {{decrement of object of volatile-qualified type 'volatile int' is deprecated}}
189 n
+= 5; // undeprecated as a DR in C++23
190 n
*= 3; // undeprecated as a DR in C++23
191 n
/= 2; // undeprecated as a DR in C++23
192 n
%= 42; // undeprecated as a DR in C++23
193 n
&= 2; // undeprecated as a DR in C++23
194 n
|= 2; // undeprecated as a DR in C++23
195 n
^= 2; // undeprecated as a DR in C++23
197 (void)__is_trivially_assignable(volatile int&, int); // no warning
199 #if __cplusplus >= 201703L
200 struct X
{ int a
, b
; };
201 volatile auto [x
, y
] = X
{1, 2}; // cxx20-warning {{volatile qualifier in structured binding declaration is deprecated}}
203 struct Y
{ volatile int a
, b
; };
204 auto [x2
, y2
] = Y
{1, 2}; // ok
207 volatile int g( // cxx20-warning {{volatile-qualified return type 'volatile int' is deprecated}}
208 volatile int n
, // cxx20-warning {{volatile-qualified parameter type 'volatile int' is deprecated}}
209 volatile int (*p
)( // cxx20-warning {{volatile-qualified return type 'volatile int' is deprecated}}
210 volatile int m
) // cxx20-warning {{volatile-qualified parameter type 'volatile int' is deprecated}}
212 #if __cplusplus >= 201103L
213 auto lambda
= []( // cxx20-warning{{volatile-qualified return type 'volatile int' is deprecated}}
214 volatile int n
) // cxx20-warning{{volatile-qualified parameter type 'volatile int' is deprecated}}
215 -> volatile int { return n
; };
218 template<typename T
> T
f(T v
); // cxx20-warning 2{{deprecated}}
219 int use_f
= f
<volatile int>(0); // FIXME: Missing "in instantiation of" note.
221 // OK, only the built-in operators are deprecated.
223 UDT(volatile const UDT
&);
224 UDT
&operator=(const UDT
&);
225 UDT
&operator=(const UDT
&) volatile;
226 UDT
operator+=(const UDT
&) volatile;
236 namespace ArithConv
{
240 bool b2
= e
== f
; // not-cxx20-warning-re {{different enumeration types ('ArithConv::E' and 'ArithConv::F'){{$}}}} cxx20-warning {{F') is deprecated}}
241 bool b3
= e
== 0.0; // cxx20-warning {{comparison of enumeration type 'ArithConv::E' with floating-point type 'double' is deprecated}}
242 bool b4
= 0.0 == f
; // cxx20-warning {{comparison of floating-point type 'double' with enumeration type 'ArithConv::F' is deprecated}}
243 int n1
= true ? e
: f
; // cxx20-warning {{conditional expression between different enumeration types ('ArithConv::E' and 'ArithConv::F') is deprecated}}
244 int n2
= true ? e
: 0.0; // cxx20-warning {{conditional expression between enumeration type 'ArithConv::E' and floating-point type 'double' is deprecated}}
247 namespace ArrayComp
{
248 int arr1
[3], arr2
[4];
249 bool b1
= arr1
== arr2
; // expected-warning {{array comparison always evaluates to false}} cxx20-warning {{comparison between two arrays is deprecated}}
250 bool b2
= arr1
< arr2
; // expected-warning {{array comparison always evaluates to a constant}} cxx20-warning {{comparison between two arrays is deprecated}}
251 __attribute__((weak
)) int arr3
[3];
252 bool b3
= arr1
== arr3
; // cxx20-warning {{comparison between two arrays is deprecated}}
253 bool b4
= arr1
< arr3
; // cxx20-warning {{comparison between two arrays is deprecated}}
254 #if __cplusplus > 201703L
255 bool b5
= arr1
<=> arr2
; // cxx20-error {{invalid operands}}
259 bool b6
= arr1
== f(); // cxx20-warning {{comparison between two arrays is deprecated}}
260 bool b7
= arr1
== +f();
264 [[deprecated
]] int f1() { // expected-note {{'f1' has been explicitly marked deprecated here}}
265 [[deprecated
]] int a
; // expected-note {{'a' has been explicitly marked deprecated here}} \
266 // expected-note {{'a' has been explicitly marked deprecated here}}
267 a
= 0; // expected-warning {{'a' is deprecated}}
268 return a
; // expected-warning {{'a' is deprecated}}
271 [[deprecated
]] void f2([[deprecated
]] int x
) { // expected-note {{'f2' has been explicitly marked deprecated here}} \
272 // expected-note {{'x' has been explicitly marked deprecated here}}
273 x
= 4; // expected-warning {{'x' is deprecated}}
277 f1(); // expected-warning {{'f1' is deprecated}}
278 f2(1); // expected-warning {{'f2' is deprecated}}
283 # 1 "/usr/include/system-header.h" 1 3
284 void system_header_function(void) throw();