[libcxx-commits] [libcxx] [libc++] Avoids using ENODATA. (PR #86165)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 9 10:12:58 PDT 2024


https://github.com/mordante updated https://github.com/llvm/llvm-project/pull/86165

>From 89830669cfd4a977006c958dd853e9f538ee6cf8 Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Thu, 14 Mar 2024 19:39:10 +0100
Subject: [PATCH 1/2] [libc++] Avoids using ENODATA.

This macro is deprecated in C++26.

Fixes https://github.com/llvm/llvm-project/issues/81360
---
 libcxx/docs/ReleaseNotes/19.rst | 5 ++++-
 libcxx/src/random.cpp           | 4 +---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index cac42f9c3c3f79..70cf3812d771aa 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -100,7 +100,10 @@ TODO
 
 ABI Affecting Changes
 ---------------------
-TODO
+
+- The optional POSIX macro ``ENODATA`` has been deprecated in C++. The
+  ``random_device`` could throw a ``system_error`` with this value. It now
+  throws ``ENOMSG``.
 
 
 Build System Changes
diff --git a/libcxx/src/random.cpp b/libcxx/src/random.cpp
index 93590af310e51a..14c6f4473d70b9 100644
--- a/libcxx/src/random.cpp
+++ b/libcxx/src/random.cpp
@@ -79,10 +79,8 @@ 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"); // TODO ENODATA -> ENOMSG
-    _LIBCPP_SUPPRESS_DEPRECATED_POP
+      __throw_system_error(ENOMSG, "random_device got EOF");
     if (s == -1) {
       if (errno != EINTR)
         __throw_system_error(errno, "random_device got an unexpected error");

>From 1fa4c5fded100b2c0003421e8285d251bfa911c3 Mon Sep 17 00:00:00 2001
From: Mark de Wever <zar-rpg at xs4all.nl>
Date: Tue, 9 Apr 2024 19:12:51 +0200
Subject: [PATCH 2/2] Update libcxx/docs/ReleaseNotes/19.rst

Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>
---
 libcxx/docs/ReleaseNotes/19.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst
index 70cf3812d771aa..c3f10ab09c0595 100644
--- a/libcxx/docs/ReleaseNotes/19.rst
+++ b/libcxx/docs/ReleaseNotes/19.rst
@@ -101,7 +101,7 @@ TODO
 ABI Affecting Changes
 ---------------------
 
-- The optional POSIX macro ``ENODATA`` has been deprecated in C++. The
+- The optional POSIX macro ``ENODATA`` has been deprecated in C++ and POSIX 2017. The
   ``random_device`` could throw a ``system_error`` with this value. It now
   throws ``ENOMSG``.
 



More information about the libcxx-commits mailing list