Skip to content

Commit fc8cbbb

Browse files
committed
[libc++] Deprecates std::errc constants.
Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
1 parent 260fe03 commit fc8cbbb

File tree

5 files changed

+116
-12
lines changed

5 files changed

+116
-12
lines changed

libcxx/include/__system_error/errc.h

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ enum class errc
5858
no_child_process, // ECHILD
5959
no_link, // ENOLINK
6060
no_lock_available, // ENOLCK
61-
no_message_available, // ENODATA
61+
no_message_available, // ENODATA // deprecated
6262
no_message, // ENOMSG
6363
no_protocol_option, // ENOPROTOOPT
6464
no_space_on_device, // ENOSPC
65-
no_stream_resources, // ENOSR
65+
no_stream_resources, // ENOSR // deprecated
6666
no_such_device_or_address, // ENXIO
6767
no_such_device, // ENODEV
6868
no_such_file_or_directory, // ENOENT
6969
no_such_process, // ESRCH
7070
not_a_directory, // ENOTDIR
7171
not_a_socket, // ENOTSOCK
72-
not_a_stream, // ENOSTR
72+
not_a_stream, // ENOSTR // deprecated
7373
not_connected, // ENOTCONN
7474
not_enough_memory, // ENOMEM
7575
not_supported, // ENOTSUP
@@ -87,7 +87,7 @@ enum class errc
8787
resource_unavailable_try_again, // EAGAIN
8888
result_out_of_range, // ERANGE
8989
state_not_recoverable, // ENOTRECOVERABLE
90-
stream_timeout, // ETIME
90+
stream_timeout, // ETIME // deprecated
9191
text_file_busy, // ETXTBSY
9292
timed_out, // ETIMEDOUT
9393
too_many_files_open_in_system, // ENFILE
@@ -113,6 +113,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD
113113
// for them:
114114

115115
// enum class errc
116+
//
117+
// LWG3869 deprecates the UNIX STREAMS macros and enum values.
118+
// This makes the code clumbersome:
119+
// - the enum value is deprecated and should show a diagnostic,
120+
// - the macro is deprecated and should _not_ show a diagnostic in this
121+
// context, and
122+
// - the macro is not always available.
123+
// This leads to the odd pushing and popping of the deprecated
124+
// diagnostic.
116125
_LIBCPP_DECLARE_STRONG_ENUM(errc){
117126
address_family_not_supported = EAFNOSUPPORT,
118127
address_in_use = EADDRINUSE,
@@ -154,30 +163,48 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
154163
no_child_process = ECHILD,
155164
no_link = ENOLINK,
156165
no_lock_available = ENOLCK,
166+
// clang-format off
167+
no_message_available _LIBCPP_DEPRECATED =
168+
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
157169
#ifdef ENODATA
158-
no_message_available = ENODATA,
170+
ENODATA
159171
#else
160-
no_message_available = ENOMSG,
172+
ENOMSG
161173
#endif
174+
_LIBCPP_SUPPRESS_DEPRECATED_POP
175+
,
176+
// clang-format on
162177
no_message = ENOMSG,
163178
no_protocol_option = ENOPROTOOPT,
164179
no_space_on_device = ENOSPC,
180+
// clang-format off
181+
no_stream_resources _LIBCPP_DEPRECATED =
182+
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
165183
#ifdef ENOSR
166-
no_stream_resources = ENOSR,
184+
ENOSR
167185
#else
168-
no_stream_resources = ENOMEM,
186+
ENOMEM
169187
#endif
188+
_LIBCPP_SUPPRESS_DEPRECATED_POP
189+
,
190+
// clang-format on
170191
no_such_device_or_address = ENXIO,
171192
no_such_device = ENODEV,
172193
no_such_file_or_directory = ENOENT,
173194
no_such_process = ESRCH,
174195
not_a_directory = ENOTDIR,
175196
not_a_socket = ENOTSOCK,
197+
// clang-format off
198+
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
199+
not_a_stream _LIBCPP_DEPRECATED =
176200
#ifdef ENOSTR
177-
not_a_stream = ENOSTR,
201+
ENOSTR
178202
#else
179-
not_a_stream = EINVAL,
203+
EINVAL
180204
#endif
205+
_LIBCPP_SUPPRESS_DEPRECATED_POP
206+
,
207+
// clang-format on
181208
not_connected = ENOTCONN,
182209
not_enough_memory = ENOMEM,
183210
not_supported = ENOTSUP,
@@ -195,11 +222,17 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
195222
resource_unavailable_try_again = EAGAIN,
196223
result_out_of_range = ERANGE,
197224
state_not_recoverable = ENOTRECOVERABLE,
225+
// clang-format off
226+
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
227+
stream_timeout _LIBCPP_DEPRECATED =
198228
#ifdef ETIME
199-
stream_timeout = ETIME,
229+
ETIME
200230
#else
201-
stream_timeout = ETIMEDOUT,
231+
ETIMEDOUT
202232
#endif
233+
_LIBCPP_SUPPRESS_DEPRECATED_POP
234+
,
235+
// clang-format on
203236
text_file_busy = ETXTBSY,
204237
timed_out = ETIMEDOUT,
205238
too_many_files_open_in_system = ENFILE,

libcxx/include/cerrno

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,17 @@ Macros:
3939
# pragma GCC system_header
4040
#endif
4141

42+
#ifdef ENODATA
43+
# pragma clang deprecated(ENODATA, "ENODATA is deprecated in ISO C++")
44+
#endif
45+
#ifdef ENOSR
46+
# pragma clang deprecated(ENOSR, "ENOSR is deprecated in ISO C++")
47+
#endif
48+
#ifdef ENOSTR
49+
# pragma clang deprecated(ENOSTR, "ENOSTR is deprecated in ISO C++")
50+
#endif
51+
#ifdef ETIME
52+
# pragma clang deprecated(ETIME, "ETIME is deprecated in ISO C++")
53+
#endif
54+
4255
#endif // _LIBCPP_CERRNO
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <cerrno>
10+
11+
// tests LWG 3869 deprecated macros.
12+
//
13+
// Note the macros may not be defined. When they are not defined the
14+
// ifdef XXX does not trigger a deprecated message. So use them in the
15+
// ifdef and test for 2 deprecated messages.
16+
17+
#include <cerrno>
18+
19+
#ifdef ENODATA
20+
[[maybe_unused]] int nodata =
21+
ENODATA; // [email protected]:* 2 {{macro 'ENODATA' has been marked as deprecated}}
22+
#endif
23+
#ifdef ENOSR
24+
[[maybe_unused]] int nosr =
25+
ENOSR; // [email protected]:* 2 {{macro 'ENOSR' has been marked as deprecated}}
26+
#endif
27+
#ifdef ENOSTR
28+
[[maybe_unused]] int nostr =
29+
ENOSTR; // [email protected]:* 2 {{macro 'ENOSTR' has been marked as deprecated}}
30+
#endif
31+
#ifdef ETIME
32+
[[maybe_unused]] int timeout =
33+
ETIME; // [email protected]:* 2 {{macro 'ETIME' has been marked as deprecated}}
34+
#endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// <system_error>
10+
11+
// enum errc {...}
12+
13+
// tests LWG 3869 deprecated enum members.
14+
15+
#include <system_error>
16+
17+
[[maybe_unused]] std::errc nodata =
18+
std::errc::no_message_available; // expected-warning {{'no_message_available' is deprecated}}
19+
[[maybe_unused]] std::errc nosr =
20+
std::errc::no_stream_resources; // expected-warning {{'no_stream_resources' is deprecated}}
21+
[[maybe_unused]] std::errc nostr = std::errc::not_a_stream; // expected-warning {{'not_a_stream' is deprecated}}
22+
[[maybe_unused]] std::errc timeout = std::errc::stream_timeout; // expected-warning {{'stream_timeout' is deprecated}}

libcxx/test/std/diagnostics/syserr/errc.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
10+
911
// <system_error>
1012

1113
// enum errc {...}

0 commit comments

Comments
 (0)