-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-libcxx Author: Mark de Wever (mordante) ChangesImplements:
Full diff: https://github.com/llvm/llvm-project/pull/80542.diff 5 Files Affected:
diff --git a/libcxx/include/__system_error/errc.h b/libcxx/include/__system_error/errc.h
index f87df86a71e15..3d49cb186877f 100644
--- a/libcxx/include/__system_error/errc.h
+++ b/libcxx/include/__system_error/errc.h
@@ -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
@@ -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
@@ -113,6 +113,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// 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,
@@ -154,30 +163,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_PUSH
#ifdef ENODATA
- no_message_available = ENODATA,
+ ENODATA
#else
- no_message_available = ENOMSG,
+ ENOMSG
#endif
+ _LIBCPP_SUPPRESS_DEPRECATED_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_PUSH
#ifdef ENOSR
- no_stream_resources = ENOSR,
+ ENOSR
#else
- no_stream_resources = ENOMEM,
+ ENOMEM
#endif
+ _LIBCPP_SUPPRESS_DEPRECATED_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
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ not_a_stream _LIBCPP_DEPRECATED =
#ifdef ENOSTR
- not_a_stream = ENOSTR,
+ ENOSTR
#else
- not_a_stream = EINVAL,
+ EINVAL
#endif
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+ ,
+ // clang-format on
not_connected = ENOTCONN,
not_enough_memory = ENOMEM,
not_supported = ENOTSUP,
@@ -195,11 +222,17 @@ _LIBCPP_DECLARE_STRONG_ENUM(errc){
resource_unavailable_try_again = EAGAIN,
result_out_of_range = ERANGE,
state_not_recoverable = ENOTRECOVERABLE,
+ // clang-format off
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ stream_timeout _LIBCPP_DEPRECATED =
#ifdef ETIME
- stream_timeout = ETIME,
+ ETIME
#else
- stream_timeout = ETIMEDOUT,
+ ETIMEDOUT
#endif
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
+ ,
+ // clang-format on
text_file_busy = ETXTBSY,
timed_out = ETIMEDOUT,
too_many_files_open_in_system = ENFILE,
diff --git a/libcxx/include/cerrno b/libcxx/include/cerrno
index 937ec23c6971a..1cb6b8ada7679 100644
--- a/libcxx/include/cerrno
+++ b/libcxx/include/cerrno
@@ -39,4 +39,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
diff --git a/libcxx/test/std/depr.cerro/cerrno.syn.verify.cpp b/libcxx/test/std/depr.cerro/cerrno.syn.verify.cpp
new file mode 100644
index 0000000000000..8257f7dd11641
--- /dev/null
+++ b/libcxx/test/std/depr.cerro/cerrno.syn.verify.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <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
diff --git a/libcxx/test/std/depr.cerro/system.error.syn.verify.cpp b/libcxx/test/std/depr.cerro/system.error.syn.verify.cpp
new file mode 100644
index 0000000000000..b6f160b1d04fb
--- /dev/null
+++ b/libcxx/test/std/depr.cerro/system.error.syn.verify.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <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}}
diff --git a/libcxx/test/std/diagnostics/syserr/errc.pass.cpp b/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
index e44cb50102e3e..4abee08ddc662 100644
--- a/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
+++ b/libcxx/test/std/diagnostics/syserr/errc.pass.cpp
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
+
// <system_error>
// enum errc {...}
|
fc8cbbb
to
8b08f3e
Compare
ad2c19a
to
ed28997
Compare
ed28997
to
0dcfe9a
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
3e2036f
to
198c47c
Compare
Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
198c47c
to
b8f04dd
Compare
Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
We get diags about …hm, looking at libcxx/include/cerrno, it looks pretty intentional. But the commit description and the changelog entry could maybe call this out more (?). |
Is there a way to opt out of this, to be able to fix async? I thought maybe defining |
Fair point the message could have been clearer. What do you mean with an opt out? This is a deprecation that we like people to fix, I expect there will be a removal which will be retroactively applied. (Note this is a change by POSIX and C++ follows its lead.) |
I mean some way (preprocessor define I suppose) that says "I have seen this deprecation message, please silence it for now". That's useful to be able to update your libc++ and then work on new deprecations asynchronously. Without opt-outs, you always have to fix all issues before you can updating again. That opens the risk that upstream lands some bug that you don't notice until the next update attempt, and if that adds a new deprecation before the new bug, you now have to fix that deprecation before you can roll in the bug fix. MSVC's STL has opt-out macros for every deprecation they add, as far as I know. That is very useful for consumers, since it makes updating independent from fixing deprecation warnings. (It's enough to have these opt-outs for a little while, not forever, of course.) (For some data points, https://autoroll.skia.org/r/libcxx-chromium/roll-history shows that libc++ updates have been very rough for us this year, with several weeks between successful updates. When things work, we usually update within hours. The last time, it took us a few weeks to clean up the iterator change in #74482 since that didn't have an effective opt-out. In the meantime, 79 changes landed. Several of them cleaned up includes, but luckily it looks like we only had to add a single Edit: Even for more traditional projects that uprev libc++ only when new LLVM releases happen, these flags could be useful: it a) allows them to update before fixing all deprecation messages and b) allows them to fix deprecation issues one-by-one and then remove the opt-out macros one by one. That way, they can be sure they don't accidentally add new uses of some deprecated thing while they work on addressing remaining deprecated issues. |
Thanks for the additional information. Typically we only add opt-out macros when we remove features, not when we add deprecation flags. I think usually these depredations only affect newer language versions. But I've added some for long deprecated features too; they were added before we had deprecated messages. I've no objection to add an opt-out macro. @ldionne any objection from your side? And should we always do this when we add a new deprecation? For example. for barrier, latch, and friends prior to C++20. |
We provide Alternatively, we could systematically introduce such macros but this is stuff that we'd be stuck with "forever" unless we agree on some kind of process to clean them up after N releases. If we do that, I'd argue that we want to remove them after a single release: if you need to silence deprecation warnings for an extended period of time, I would argue you shouldn't compile with deprecation warnings turned into errors.
This is an example where the deprecation + removal process is made more complicated. So we would do this, I guess?
Or would the deprecation-warning opt-out also imply that we should have the same for the removal from C++20? If that's the expectation, I would push back on that: we need the ability to make breaking changes (not huge ones) in less than 1 year. |
FWIW, a per-deprecation warning disable toggle for a single release would be more than enough for our use case, and it would make our lifes a lot easier. |
ENOSTR, ETIME, ENODATA, and ENOSR are deprecated by POSIX and C++23. This change also turns on the deprecation warnings used by Chromium. See also: https://wg21.link/LWG3869 llvm/llvm-project#80542 https://buganizer.corp.google.com/issues/331100926 PiperOrigin-RevId: 619551374 Change-Id: Ica8d5008cbee52ce88d58a1fcb79dbe794045bae
ENOSTR, ETIME, ENODATA, and ENOSR are deprecated by POSIX and C++23. This change also turns on the deprecation warnings used by Chromium. See also: https://wg21.link/LWG3869 llvm/llvm-project#80542 https://buganizer.corp.google.com/issues/331100926 PiperOrigin-RevId: 619551374 Change-Id: Ica8d5008cbee52ce88d58a1fcb79dbe794045bae
We started observing an interesting behavior in our codebase after this patch, and let me explain it with a simple example: Case 1: There is no
Case2: There is a
Is this the expected behavior? |
At first blush, I was surprised by this. However, That said, this is obsolete for strictly conforming POSIX and that requires defining |
@gulfemsavrun I like to discuss the way forward before deciding the changes I'm going to make. I agree with @AaronBallman the behaviour is correct. However I wonder whether we're doing our users a service with the correct behaviour. When C++ removes the POSIX macros from I think we should keep the behaviour for the For the macros I wonder what the best way would be:
Personally I'm leaning towards 2, but I like to hear your opinions. |
FWIW, the POSIX macros can be deprecated in Personally, I think deprecation is only valuable if users are warned about it explicitly. So I tend to lean towards (3) because it gets the notification out to users. It might be worth reaching out to libc folks supporting POSIX to see if they'd consider adding the deprecation warnings to errno.h as well? |
Personally, I'd tend towards (1), i.e. do not deprecate the macros at all. After re-consideration, I feel like we might be overstepping the boundary between libc++ and the C Standard Library. We don't define these @nico Were you asking for an opt-out for the |
The thing is, there's a name collision here. Linux never implemented STREAMS and thus never added these error codes as defined in POSIX, but they did define ENODATA as a Linux specific error used (afaik) only to mean "the extended attribute you tried to reference does not exist". This code is not deprecated and is often necessary in code that deals with extended attributes. For example: https://godbolt.org/z/xsqsas5Ea. This isn't really using anything deprecated and shouldn't warn when compiled on Linux. |
Re above: So here again, simply not deprecating the macros in libc++ and letting the C Library handle that business seems to do the right thing. I think this reinforces that we should go for (1). |
LWG3869 Deprecate std::errc constants related to UNIX STREAMS deprecates the POSIX macros ENODATA, ENOSR, ENOSTR, and ETIME. These were deprecated in libc++ in llvm#80542. Based on the post commit feedback the macro are no longer deprecated. Instead libc++ leaves the deprecation to the provider of errno.h.
Based on the feedback and a private discussion with Louis I've implemented option 1 in #88296. @gulfemsavrun That should disable the deprecation message in your |
Thanks for the update @mordante! |
FWIW, I'm also happy enough going with option 1, so thank you for the quick fix here! |
Yes, correct, just the errno.h macros. Thanks! |
LWG3869 Deprecate std::errc constants related to UNIX STREAMS deprecates the POSIX macros ENODATA, ENOSR, ENOSTR, and ETIME. These were deprecated in libc++ in #80542. Based on the post commit feedback the macro are no longer deprecated. Instead libc++ leaves the deprecation to the provider of errno.h. --------- Co-authored-by: Hristo Hristov <[email protected]> Co-authored-by: Louis Dionne <[email protected]>
LWG3869 Deprecate std::errc constants related to UNIX STREAMS deprecates the POSIX macros ENODATA, ENOSR, ENOSTR, and ETIME. These were deprecated in libc++ in llvm#80542. Based on the post commit feedback the macro are no longer deprecated. Instead libc++ leaves the deprecation to the provider of errno.h. --------- Co-authored-by: Hristo Hristov <[email protected]> Co-authored-by: Louis Dionne <[email protected]>
Chromium (libc++) change: llvm/llvm-project#80542 commit e3fe3e833ae34840f04f0999fa3538c554010e9b Author: Mark de Wever <[email protected]> Date: Thu Mar 21 12:14:24 2024 +0100 [libc++] Deprecates std::errc constants. (#80542) Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
Chromium (libc++) change: llvm/llvm-project#80542 commit e3fe3e833ae34840f04f0999fa3538c554010e9b Author: Mark de Wever <[email protected]> Date: Thu Mar 21 12:14:24 2024 +0100 [libc++] Deprecates std::errc constants. (#80542) Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
Chromium (libc++) change: llvm/llvm-project#80542 commit e3fe3e833ae34840f04f0999fa3538c554010e9b Author: Mark de Wever <[email protected]> Date: Thu Mar 21 12:14:24 2024 +0100 [libc++] Deprecates std::errc constants. (#80542) Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
Chromium (libc++) change: llvm/llvm-project#80542 commit e3fe3e833ae34840f04f0999fa3538c554010e9b Author: Mark de Wever <[email protected]> Date: Thu Mar 21 12:14:24 2024 +0100 [libc++] Deprecates std::errc constants. (#80542) Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
Chromium (libc++) change: llvm/llvm-project#80542 commit e3fe3e833ae34840f04f0999fa3538c554010e9b Author: Mark de Wever <[email protected]> Date: Thu Mar 21 12:14:24 2024 +0100 [libc++] Deprecates std::errc constants. (#80542) Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
Chromium (libc++) change: llvm/llvm-project#80542 commit e3fe3e833ae34840f04f0999fa3538c554010e9b Author: Mark de Wever <[email protected]> Date: Thu Mar 21 12:14:24 2024 +0100 [libc++] Deprecates std::errc constants. (#80542) Implements: - LWG3869 Deprecate std::errc constants related to UNIX STREAMS
LWG3869 Deprecate std::errc constants related to UNIX STREAMS deprecates the POSIX macros ENODATA, ENOSR, ENOSTR, and ETIME. These were deprecated in libc++ in llvm/llvm-project#80542. Based on the post commit feedback the macro are no longer deprecated. Instead libc++ leaves the deprecation to the provider of errno.h. --------- Co-authored-by: Hristo Hristov <[email protected]> Co-authored-by: Louis Dionne <[email protected]> NOKEYCHECK=True GitOrigin-RevId: 910ec6ff6dd9ed031e31800c70740fdd17cc1c2a
Implements: