Skip to content

Commit 0dcfe9a

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

File tree

7 files changed

+135
-14
lines changed

7 files changed

+135
-14
lines changed

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
"`3847 <https://wg21.link/LWG3847>`__","``ranges::to`` can still return views","February 2023","|Complete|","17.0","|ranges|"
296296
"`3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","February 2023","","",""
297297
"`3865 <https://wg21.link/LWG3865>`__","Sorting a range of ``pairs``","February 2023","|Complete|","17.0","|ranges|"
298-
"`3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","February 2023","","",""
298+
"`3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","February 2023","|Complete|","19.0",""
299299
"`3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","February 2023","","",""
300300
"`3871 <https://wg21.link/LWG3871>`__","Adjust note about ``terminate``","February 2023","","",""
301301
"`3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","February 2023","","",""

libcxx/include/__system_error/errc.h

Lines changed: 58 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
@@ -107,12 +107,34 @@ enum class errc
107107
# pragma GCC system_header
108108
#endif
109109

110+
// The method of pushing and popping the diagnostics fails for GCC. GCC does
111+
// not recognize the pragma's used to generate deprecated diagnostics for
112+
// macros. So GCC does not need the pushing and popping.
113+
//
114+
// TODO Remove this when the deprecated constants are removed.
115+
#if defined(_LIBCPP_COMPILER_CLANG_BASED)
116+
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH _LIBCPP_SUPPRESS_DEPRECATED_PUSH
117+
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP _LIBCPP_SUPPRESS_DEPRECATED_POP
118+
#else
119+
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
120+
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
121+
#endif
122+
110123
_LIBCPP_BEGIN_NAMESPACE_STD
111124

112125
// Some error codes are not present on all platforms, so we provide equivalents
113126
// for them:
114127

115128
// enum class errc
129+
//
130+
// LWG3869 deprecates the UNIX STREAMS macros and enum values.
131+
// This makes the code clumbersome:
132+
// - the enum value is deprecated and should show a diagnostic,
133+
// - the macro is deprecated and should _not_ show a diagnostic in this
134+
// context, and
135+
// - the macro is not always available.
136+
// This leads to the odd pushing and popping of the deprecated
137+
// diagnostic.
116138
_LIBCPP_DECLARE_STRONG_ENUM(errc){
117139
address_family_not_supported = EAFNOSUPPORT,
118140
address_in_use = EADDRINUSE,
@@ -154,30 +176,48 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
154176
no_child_process = ECHILD,
155177
no_link = ENOLINK,
156178
no_lock_available = ENOLCK,
179+
// clang-format off
180+
no_message_available _LIBCPP_DEPRECATED =
181+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
157182
#ifdef ENODATA
158-
no_message_available = ENODATA,
183+
ENODATA
159184
#else
160-
no_message_available = ENOMSG,
185+
ENOMSG
161186
#endif
187+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
188+
,
189+
// clang-format on
162190
no_message = ENOMSG,
163191
no_protocol_option = ENOPROTOOPT,
164192
no_space_on_device = ENOSPC,
193+
// clang-format off
194+
no_stream_resources _LIBCPP_DEPRECATED =
195+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
165196
#ifdef ENOSR
166-
no_stream_resources = ENOSR,
197+
ENOSR
167198
#else
168-
no_stream_resources = ENOMEM,
199+
ENOMEM
169200
#endif
201+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
202+
,
203+
// clang-format on
170204
no_such_device_or_address = ENXIO,
171205
no_such_device = ENODEV,
172206
no_such_file_or_directory = ENOENT,
173207
no_such_process = ESRCH,
174208
not_a_directory = ENOTDIR,
175209
not_a_socket = ENOTSOCK,
210+
// clang-format off
211+
not_a_stream _LIBCPP_DEPRECATED =
212+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
176213
#ifdef ENOSTR
177-
not_a_stream = ENOSTR,
214+
ENOSTR
178215
#else
179-
not_a_stream = EINVAL,
216+
EINVAL
180217
#endif
218+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
219+
,
220+
// clang-format on
181221
not_connected = ENOTCONN,
182222
not_enough_memory = ENOMEM,
183223
not_supported = ENOTSUP,
@@ -195,11 +235,17 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
195235
resource_unavailable_try_again = EAGAIN,
196236
result_out_of_range = ERANGE,
197237
state_not_recoverable = ENOTRECOVERABLE,
238+
// clang-format off
239+
stream_timeout _LIBCPP_DEPRECATED =
240+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
198241
#ifdef ETIME
199-
stream_timeout = ETIME,
242+
ETIME
200243
#else
201-
stream_timeout = ETIMEDOUT,
244+
ETIMEDOUT
202245
#endif
246+
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
247+
,
248+
// clang-format on
203249
text_file_busy = ETXTBSY,
204250
timed_out = ETIMEDOUT,
205251
too_many_files_open_in_system = ENFILE,

libcxx/include/cerrno

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

41+
#ifdef ENODATA
42+
# pragma clang deprecated(ENODATA, "ENODATA is deprecated in ISO C++")
43+
#endif
44+
#ifdef ENOSR
45+
# pragma clang deprecated(ENOSR, "ENOSR is deprecated in ISO C++")
46+
#endif
47+
#ifdef ENOSTR
48+
# pragma clang deprecated(ENOSTR, "ENOSTR is deprecated in ISO C++")
49+
#endif
50+
#ifdef ETIME
51+
# pragma clang deprecated(ETIME, "ETIME is deprecated in ISO C++")
52+
#endif
53+
4154
#endif // _LIBCPP_CERRNO

libcxx/src/random.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ unsigned random_device::operator()() {
7979
char* p = reinterpret_cast<char*>(&r);
8080
while (n > 0) {
8181
ssize_t s = read(__f_, p, n);
82+
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
8283
if (s == 0)
83-
__throw_system_error(ENODATA, "random_device got EOF");
84+
__throw_system_error(ENODATA, "random_device got EOF"); // TODO ENODATA -> ENOMSG
85+
_LIBCPP_SUPPRESS_DEPRECATED_POP
8486
if (s == -1) {
8587
if (errno != EINTR)
8688
__throw_system_error(errno, "random_device got an unexpected error");
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
// UNSUPPORTED: clang-modules-build
10+
11+
// <cerrno>
12+
13+
// tests LWG 3869 deprecated macros.
14+
//
15+
// Note the macros may not be defined. When they are not defined the
16+
// ifdef XXX does not trigger a deprecated message. So use them in the
17+
// ifdef and test for 2 deprecated messages.
18+
19+
#include <cerrno>
20+
21+
#ifdef ENODATA
22+
[[maybe_unused]] int nodata =
23+
ENODATA; // [email protected]:* 2 {{macro 'ENODATA' has been marked as deprecated}}
24+
#endif
25+
#ifdef ENOSR
26+
[[maybe_unused]] int nosr =
27+
ENOSR; // [email protected]:* 2 {{macro 'ENOSR' has been marked as deprecated}}
28+
#endif
29+
#ifdef ENOSTR
30+
[[maybe_unused]] int nostr =
31+
ENOSTR; // [email protected]:* 2 {{macro 'ENOSTR' has been marked as deprecated}}
32+
#endif
33+
#ifdef ETIME
34+
[[maybe_unused]] int timeout =
35+
ETIME; // [email protected]:* 2 {{macro 'ETIME' has been marked as deprecated}}
36+
#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)