Skip to content

[libc++] Deprecates std::errc constants. #80542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx23Issues.csv
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
"`3847 <https://wg21.link/LWG3847>`__","``ranges::to`` can still return views","February 2023","|Complete|","17.0","|ranges|"
"`3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","February 2023","","",""
"`3865 <https://wg21.link/LWG3865>`__","Sorting a range of ``pairs``","February 2023","|Complete|","17.0","|ranges|"
"`3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","February 2023","","",""
"`3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","February 2023","|Complete|","19.0",""
"`3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","February 2023","","",""
"`3871 <https://wg21.link/LWG3871>`__","Adjust note about ``terminate``","February 2023","","",""
"`3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","February 2023","","",""
Expand Down
70 changes: 58 additions & 12 deletions libcxx/include/__system_error/errc.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ enum class errc
no_child_process, // ECHILD
no_link, // ENOLINK
no_lock_available, // ENOLCK
no_message_available, // ENODATA
no_message_available, // ENODATA // deprecated
no_message, // ENOMSG
no_protocol_option, // ENOPROTOOPT
no_space_on_device, // ENOSPC
no_stream_resources, // ENOSR
no_stream_resources, // ENOSR // deprecated
no_such_device_or_address, // ENXIO
no_such_device, // ENODEV
no_such_file_or_directory, // ENOENT
no_such_process, // ESRCH
not_a_directory, // ENOTDIR
not_a_socket, // ENOTSOCK
not_a_stream, // ENOSTR
not_a_stream, // ENOSTR // deprecated
not_connected, // ENOTCONN
not_enough_memory, // ENOMEM
not_supported, // ENOTSUP
Expand All @@ -87,7 +87,7 @@ enum class errc
resource_unavailable_try_again, // EAGAIN
result_out_of_range, // ERANGE
state_not_recoverable, // ENOTRECOVERABLE
stream_timeout, // ETIME
stream_timeout, // ETIME // deprecated
text_file_busy, // ETXTBSY
timed_out, // ETIMEDOUT
too_many_files_open_in_system, // ENFILE
Expand All @@ -107,12 +107,34 @@ enum class errc
# pragma GCC system_header
#endif

// The method of pushing and popping the diagnostics fails for GCC. GCC does
// not recognize the pragma's used to generate deprecated diagnostics for
// macros. So GCC does not need the pushing and popping.
//
// TODO Remove this when the deprecated constants are removed.
#if defined(_LIBCPP_COMPILER_CLANG_BASED)
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH _LIBCPP_SUPPRESS_DEPRECATED_PUSH
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP _LIBCPP_SUPPRESS_DEPRECATED_POP
#else
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
# define _LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

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

// enum class errc
//
// LWG3869 deprecates the UNIX STREAMS macros and enum values.
// This makes the code clumbersome:
// - the enum value is deprecated and should show a diagnostic,
// - the macro is deprecated and should _not_ show a diagnostic in this
// context, and
// - the macro is not always available.
// This leads to the odd pushing and popping of the deprecated
// diagnostic.
_LIBCPP_DECLARE_STRONG_ENUM(errc){
address_family_not_supported = EAFNOSUPPORT,
address_in_use = EADDRINUSE,
Expand Down Expand Up @@ -154,30 +176,48 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
no_child_process = ECHILD,
no_link = ENOLINK,
no_lock_available = ENOLCK,
// clang-format off
no_message_available _LIBCPP_DEPRECATED =
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
#ifdef ENODATA
no_message_available = ENODATA,
ENODATA
#else
no_message_available = ENOMSG,
ENOMSG
#endif
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
,
// clang-format on
no_message = ENOMSG,
no_protocol_option = ENOPROTOOPT,
no_space_on_device = ENOSPC,
// clang-format off
no_stream_resources _LIBCPP_DEPRECATED =
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
#ifdef ENOSR
no_stream_resources = ENOSR,
ENOSR
#else
no_stream_resources = ENOMEM,
ENOMEM
#endif
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
,
// clang-format on
no_such_device_or_address = ENXIO,
no_such_device = ENODEV,
no_such_file_or_directory = ENOENT,
no_such_process = ESRCH,
not_a_directory = ENOTDIR,
not_a_socket = ENOTSOCK,
// clang-format off
not_a_stream _LIBCPP_DEPRECATED =
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
#ifdef ENOSTR
not_a_stream = ENOSTR,
ENOSTR
#else
not_a_stream = EINVAL,
EINVAL
#endif
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
,
// clang-format on
not_connected = ENOTCONN,
not_enough_memory = ENOMEM,
not_supported = ENOTSUP,
Expand All @@ -195,11 +235,17 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
resource_unavailable_try_again = EAGAIN,
result_out_of_range = ERANGE,
state_not_recoverable = ENOTRECOVERABLE,
// clang-format off
stream_timeout _LIBCPP_DEPRECATED =
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_PUSH
#ifdef ETIME
stream_timeout = ETIME,
ETIME
#else
stream_timeout = ETIMEDOUT,
ETIMEDOUT
#endif
_LIBCPP_SUPPRESS_DEPRECATED_ERRC_POP
,
// clang-format on
text_file_busy = ETXTBSY,
timed_out = ETIMEDOUT,
too_many_files_open_in_system = ENFILE,
Expand Down
13 changes: 13 additions & 0 deletions libcxx/include/cerrno
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ Macros:
# pragma GCC system_header
#endif

#ifdef ENODATA
# pragma clang deprecated(ENODATA, "ENODATA is deprecated in ISO C++")
#endif
#ifdef ENOSR
# pragma clang deprecated(ENOSR, "ENOSR is deprecated in ISO C++")
#endif
#ifdef ENOSTR
# pragma clang deprecated(ENOSTR, "ENOSTR is deprecated in ISO C++")
#endif
#ifdef ETIME
# pragma clang deprecated(ETIME, "ETIME is deprecated in ISO C++")
#endif

#endif // _LIBCPP_CERRNO
4 changes: 3 additions & 1 deletion libcxx/src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ unsigned random_device::operator()() {
char* p = reinterpret_cast<char*>(&r);
while (n > 0) {
ssize_t s = read(__f_, p, n);
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
if (s == 0)
__throw_system_error(ENODATA, "random_device got EOF");
__throw_system_error(ENODATA, "random_device got EOF"); // TODO ENODATA -> ENOMSG
_LIBCPP_SUPPRESS_DEPRECATED_POP
if (s == -1) {
if (errno != EINTR)
__throw_system_error(errno, "random_device got an unexpected error");
Expand Down
37 changes: 37 additions & 0 deletions libcxx/test/std/depr.cerro/cerrno.syn.verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: clang-modules-build
// UNSUPPORTED: apple-clang && c++03

// <cerrno>

// tests LWG 3869 deprecated macros.
//
// Note the macros may not be defined. When they are not defined the
// ifdef XXX does not trigger a deprecated message. So use them in the
// ifdef and test for 2 deprecated messages.

#include <cerrno>

#ifdef ENODATA
[[maybe_unused]] int nodata =
ENODATA; // [email protected]:* 2 {{macro 'ENODATA' has been marked as deprecated}}
#endif
#ifdef ENOSR
[[maybe_unused]] int nosr =
ENOSR; // [email protected]:* 2 {{macro 'ENOSR' has been marked as deprecated}}
#endif
#ifdef ENOSTR
[[maybe_unused]] int nostr =
ENOSTR; // [email protected]:* 2 {{macro 'ENOSTR' has been marked as deprecated}}
#endif
#ifdef ETIME
[[maybe_unused]] int timeout =
ETIME; // [email protected]:* 2 {{macro 'ETIME' has been marked as deprecated}}
#endif
28 changes: 28 additions & 0 deletions libcxx/test/std/depr.cerro/system.error.syn.verify.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// These macros do not seem to behave as expected on all Apple platforms.
// Since the macros are not provided newer POSIX versions it is expected the
// macros will be retroactively removed from C++. (The deprecation was
// retroactively.)
// UNSUPPORTED: apple-clang && (c++03 || clang-modules-build)

// <system_error>

// enum errc {...}

// tests LWG 3869 deprecated enum members.

#include <system_error>

[[maybe_unused]] std::errc nodata =
std::errc::no_message_available; // expected-warning {{'no_message_available' is deprecated}}
[[maybe_unused]] std::errc nosr =
std::errc::no_stream_resources; // expected-warning {{'no_stream_resources' is deprecated}}
[[maybe_unused]] std::errc nostr = std::errc::not_a_stream; // expected-warning {{'not_a_stream' is deprecated}}
[[maybe_unused]] std::errc timeout = std::errc::stream_timeout; // expected-warning {{'stream_timeout' is deprecated}}
2 changes: 2 additions & 0 deletions libcxx/test/std/diagnostics/syserr/errc.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//

// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS

// <system_error>

// enum errc {...}
Expand Down