[gcc r17-4838] libstdc++: Remove preprocessor checks for EPERM
Jonathan Wakely
redi@gcc.gnu.org
Fri Oct 2 13:52:12 GMT 2026
https://gcc.gnu.org/g:87c14b9896b54696fbec7d8824eee135baca1f4d
commit r17-4838-g87c14b9896b54696fbec7d8824eee135baca1f4d
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Sep 25 17:05:39 2026 +0100
libstdc++: Remove preprocessor checks for EPERM
The config/os/mingw32-w64/error_constants.h and
config/os/mingw32/error_constants.h headers check `#ifdef EPERM` before
using it, but I think that's completely redundant. Windows and all
versions of MinGW and mingw-w64 define EPERM and always have done as far
as I can tell. And all UNIX-like and POSIX-based targets define it.
We already have other code that uses EPERM without checking if it's
defined, and that would not compile if it wasn't present for the target.
Remove the #ifdef from those headers so that we use it unconditionally,
and remove some other checks and comments that assume it can be absent.
libstdc++-v3/ChangeLog:
* config/os/mingw32-w64/error_constants.h: Use EPERM without
checking if it's defined.
* config/os/mingw32/error_constants.h: Likewise.
* src/c++11/system_error.cc: Likewise.
* src/c++17/fs_dir.cc (fs::recursive_directory_iterator::__erase):
Likewise.
* testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc:
Use errc::operation_not_permitted without checking if EPERM is
defined.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Diff:
---
libstdc++-v3/config/os/mingw32-w64/error_constants.h | 2 --
libstdc++-v3/config/os/mingw32/error_constants.h | 2 --
libstdc++-v3/src/c++11/system_error.cc | 4 ----
libstdc++-v3/src/c++17/fs_dir.cc | 6 +-----
.../testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc | 4 ----
5 files changed, 1 insertion(+), 17 deletions(-)
diff --git a/libstdc++-v3/config/os/mingw32-w64/error_constants.h b/libstdc++-v3/config/os/mingw32-w64/error_constants.h
index f2a4fb579042..eca02eeecc76 100644
--- a/libstdc++-v3/config/os/mingw32-w64/error_constants.h
+++ b/libstdc++-v3/config/os/mingw32-w64/error_constants.h
@@ -118,9 +118,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
operation_canceled = ECANCELED,
operation_in_progress = EINPROGRESS,
-#ifdef EPERM
operation_not_permitted = EPERM,
-#endif
operation_not_supported = EOPNOTSUPP,
#ifdef EWOULDBLOCK
operation_would_block = EWOULDBLOCK,
diff --git a/libstdc++-v3/config/os/mingw32/error_constants.h b/libstdc++-v3/config/os/mingw32/error_constants.h
index 2586eed5b037..eeeeedc5c611 100644
--- a/libstdc++-v3/config/os/mingw32/error_constants.h
+++ b/libstdc++-v3/config/os/mingw32/error_constants.h
@@ -104,9 +104,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
// operation_canceled = ECANCELED,
// operation_in_progress = EINPROGRESS,
-#ifdef EPERM
operation_not_permitted = EPERM,
-#endif
// operation_not_supported = EOPNOTSUPP,
#ifdef EWOULDBLOCK
operation_would_block = EWOULDBLOCK,
diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc
index 851f51acd404..a251fe6a50e2 100644
--- a/libstdc++-v3/src/c++11/system_error.cc
+++ b/libstdc++-v3/src/c++11/system_error.cc
@@ -275,11 +275,7 @@ namespace
X (NONPAGED_SYSTEM_RESOURCES, EAGAIN);
X (NOT_ENOUGH_MEMORY, ENOMEM);
X (NOT_ENOUGH_QUOTA, EIO);
-#ifdef EPERM
X (NOT_OWNER, EPERM);
-#else
- X (NOT_OWNER, EACCES);
-#endif
X (NOT_SAME_DEVICE, EXDEV);
X (NOT_SUPPORTED, ENOSYS);
X (NO_DATA, EPIPE);
diff --git a/libstdc++-v3/src/c++17/fs_dir.cc b/libstdc++-v3/src/c++17/fs_dir.cc
index 7cced0db823b..f0f613ba2c51 100644
--- a/libstdc++-v3/src/c++17/fs_dir.cc
+++ b/libstdc++-v3/src/c++17/fs_dir.cc
@@ -515,13 +515,9 @@ fs::recursive_directory_iterator::__erase(error_code* ecptr)
// We did not have a cached type, so it's possible that top.entry
// is actually a directory, and that's why the unlink above failed.
const int err = ec.value();
-#ifdef EPERM
// POSIX.1-2017 says unlink on a directory returns EPERM,
- // but LSB allows EISDIR too. Some targets don't even define EPERM.
+ // but LSB allows EISDIR too.
bool is_dir = err == EPERM || err == EISDIR;
-#else
- bool is_dir = err == EISDIR;
-#endif
#if ! _GLIBCXX_HAVE_UNLINKAT
// Without unlinkat, _Dir::unlink uses ::remove, which retries as
// rmdir for a directory. Unlinking a *non-empty* directory then
diff --git a/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc b/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc
index 1b1a950c2b0b..13f4b385e385 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc
@@ -121,11 +121,7 @@ void test01()
#endif
TEST_ERRC(operation_in_progress);
-
-#ifdef EPERM
TEST_ERRC(operation_not_permitted);
-#endif
-
TEST_ERRC(operation_not_supported);
#ifdef EWOULDBLOCK
More information about the Libstdc++-cvs
mailing list