public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators
@ 2022-03-11 15:20 redi at gcc dot gnu.org
2022-09-22 10:47 ` [Bug libstdc++/104883] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-11 15:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104883
Bug ID: 104883
Summary: <system_error> should define all std::errc enumerators
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Currently we only define std::errc enumerators when the OS defines the
corresponding errno macro:
#ifdef EOVERFLOW
value_too_large = EOVERFLOW,
#endif
Which causes errors when we rely on that being present, e.g. for AVR:
/home/jwakely/src/gcc/build-avr/avr/libstdc++-v3/include/charconv: In function
‘std::to_chars_result std::__detail::__to_chars(char*, char*, _Tp, int)’:
/home/jwakely/src/gcc/build-avr/avr/libstdc++-v3/include/charconv:132:28:
error: ‘value_too_large’ is not a member of ‘std::errc’; did you mean
‘file_too_large’?
132 | __res.ec = errc::value_too_large;
| ^~~~~~~~~~~~~~~
| file_too_large
And src/filesystem/ops-common.h does this to workaround the fact that
std::errc::not_supported isn't always defined:
inline error_code
__unsupported() noexcept
{
#if defined ENOTSUP
return std::make_error_code(std::errc::not_supported);
#elif defined EOPNOTSUPP
// This is supposed to be for socket operations
return std::make_error_code(std::errc::operation_not_supported);
#else
return std::make_error_code(std::errc::invalid_argument);
#endif
}
We should consider defining all the enumerators unconditionally, picking values
outside the range used by the OS for <errno.h> constants, e.g.
#ifdef EOVERFLOW
value_too_large = EOVERFLOW,
#else
value_too_large = 1001,
#endif
The tricky part is picking a value range that doesn't clash with the OS. For
the OS-specific headers such as config/os/mingw32-w64/error_constants.h we can
just inspect <errno.h> and make an educated choice. For
config/os/generic/error_constants.h maybe we want to do something in configure
or with the preprocessor to find the largest value among all the errno macros
that *are* defined, and add 100. Or just take a gamble and assume the OS uses
small numbers and we can start from 1000, or 32000, or something.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/104883] <system_error> should define all std::errc enumerators
2022-03-11 15:20 [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators redi at gcc dot gnu.org
@ 2022-09-22 10:47 ` redi at gcc dot gnu.org
2022-09-22 21:59 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-22 10:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104883
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
From PR 1007008 comment 2:
-- >8 --
We could do something like this for each enumerator:
#ifdef EFOO
foo = EFOO,
#else
foo = _GLIBCXX_ERRC_ORIGIN + __LINE__,
#endif
Where _GLIBCXX_ERRC_ORIGIN is some value intended to be higher than the highest
errno value on the OS. We only need fewer than 100 errc enumerators so
INT_MAX/2 might be OK.
We can use #line to set the __LINE__ to a fixed value in the file, so that the
constants don't change if we add/remove lines before the errc definition.
-- >8 --
We can use a default _GLIBCXX_ERRC_ORIGIN value, and allow it to be overridden
in config/os/*/os_defines.h if the default doesn't work.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/104883] <system_error> should define all std::errc enumerators
2022-03-11 15:20 [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators redi at gcc dot gnu.org
2022-09-22 10:47 ` [Bug libstdc++/104883] " redi at gcc dot gnu.org
@ 2022-09-22 21:59 ` redi at gcc dot gnu.org
2023-02-01 21:07 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-22 21:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104883
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-09-22
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Created attachment 53613
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53613&action=edit
Generate error_constants.h from <errno.h>
Instead of having several very similar target-specific headers with
slightly different sets of enumerators, generate the error_constants.h
file as part of the build. This ensures that all enumerators are always
defined, with the value from the corresponding errno macro if present,
or a libstdc++-specific alternative value.
The libstdc++-specific values will be values greater than the positive
integer _GLIBCXX_ERRC_ORIGIN, which defaults to 9999 but can be set in
os_defines.h if a more suitable value exists for the OS (e.g. ELAST
could be used for BSD targets).
The advantage of doing this is that we get a header that can be used
freestanding, but with values that match the hosted errno.h (if one exists on
the target).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/104883] <system_error> should define all std::errc enumerators
2022-03-11 15:20 [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators redi at gcc dot gnu.org
2022-09-22 10:47 ` [Bug libstdc++/104883] " redi at gcc dot gnu.org
2022-09-22 21:59 ` redi at gcc dot gnu.org
@ 2023-02-01 21:07 ` cvs-commit at gcc dot gnu.org
2023-02-01 21:23 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-01 21:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104883
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:2d2e163d12f64a5e68f9e0381751ed9d5d6d3617
commit r13-5638-g2d2e163d12f64a5e68f9e0381751ed9d5d6d3617
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Jan 31 22:16:31 2023 +0000
libstdc++: Fix build failures for avr
The abr-libc <errno.h> does not define EOVERFLOW, which means that
std::errc::value_too_large is not defined, and so <charconv> cannot be
compiled. Define value_too_large for avr with a value that does not
clash with any that is defined in <errno.h>. This is a kluge to fix
bootstrap for avr; it can be removed after PR libstdc++/104883 is
resolved.
The avr-libc <errno.h> fails to meet the C and POSIX requirements that
each error macro has a distinct integral value, and is usable in #if
directives. Add a special case for avr to system_error.cc so that only
the valid errors are recognized. Also disable the errno checks in
std::filesystem::remove_all that assume a meaningful value for errno.
On avr-libc <unistd.h> exists but does not define the POSIX functions
needed by std::filesystem, so _GLIBCXX_HAVE_UNISTD_H is not sufficient
to check for basic POSIX APIs. Check !defined __AVR__ as well as
_GLIBCXX_HAVE_UNISTD_H before using those functions. This is a kluge and
we should really have a specific macro that says the required functions
are available.
libstdc++-v3/ChangeLog:
* config/os/generic/error_constants.h (errc::value_too_large)
[__AVR__]: Define.
* src/c++11/system_error.cc
(system_category::default_error_condition) [__AVR__]: Only match
recognize values equal to EDOM, ERANGE, ENOSYS and EINTR.
* src/c++17/fs_ops.cc (fs::current_path) [__AVR__]: Do not check
for ENOENT etc. in switch.
(fs::remove_all) [__AVR__]: Likewise.
* src/filesystem/ops-common.h [__AVR__]: Do not use POSIX open,
close etc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/104883] <system_error> should define all std::errc enumerators
2022-03-11 15:20 [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators redi at gcc dot gnu.org
` (2 preceding siblings ...)
2023-02-01 21:07 ` cvs-commit at gcc dot gnu.org
@ 2023-02-01 21:23 ` redi at gcc dot gnu.org
2023-02-02 9:34 ` cvs-commit at gcc dot gnu.org
2023-03-16 16:51 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-02-01 21:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104883
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> Which causes errors when we rely on that being present, e.g. for AVR:
>
> /home/jwakely/src/gcc/build-avr/avr/libstdc++-v3/include/charconv: In
> function ‘std::to_chars_result std::__detail::__to_chars(char*, char*, _Tp,
> int)’:
> /home/jwakely/src/gcc/build-avr/avr/libstdc++-v3/include/charconv:132:28:
> error: ‘value_too_large’ is not a member of ‘std::errc’; did you mean
> ‘file_too_large’?
> 132 | __res.ec = errc::value_too_large;
> | ^~~~~~~~~~~~~~~
> | file_too_large
This specific problem is now fixed for avr, but the general problem remains.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/104883] <system_error> should define all std::errc enumerators
2022-03-11 15:20 [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators redi at gcc dot gnu.org
` (3 preceding siblings ...)
2023-02-01 21:23 ` redi at gcc dot gnu.org
@ 2023-02-02 9:34 ` cvs-commit at gcc dot gnu.org
2023-03-16 16:51 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-02 9:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104883
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:aa18735f7aa99b40c56b3e3aacb1b28cb805bb90
commit r12-9099-gaa18735f7aa99b40c56b3e3aacb1b28cb805bb90
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Jan 31 22:16:31 2023 +0000
libstdc++: Fix build failures for avr
The abr-libc <errno.h> does not define EOVERFLOW, which means that
std::errc::value_too_large is not defined, and so <charconv> cannot be
compiled. Define value_too_large for avr with a value that does not
clash with any that is defined in <errno.h>. This is a kluge to fix
bootstrap for avr; it can be removed after PR libstdc++/104883 is
resolved.
The avr-libc <errno.h> fails to meet the C and POSIX requirements that
each error macro has a distinct integral value, and is usable in #if
directives. Add a special case for avr to system_error.cc so that only
the valid errors are recognized. Also disable the errno checks in
std::filesystem::remove_all that assume a meaningful value for errno.
On avr-libc <unistd.h> exists but does not define the POSIX functions
needed by std::filesystem, so _GLIBCXX_HAVE_UNISTD_H is not sufficient
to check for basic POSIX APIs. Check !defined __AVR__ as well as
_GLIBCXX_HAVE_UNISTD_H before using those functions. This is a kluge and
we should really have a specific macro that says the required functions
are available.
libstdc++-v3/ChangeLog:
* config/os/generic/error_constants.h (errc::value_too_large)
[__AVR__]: Define.
* src/c++11/system_error.cc
(system_category::default_error_condition) [__AVR__]: Only match
recognize values equal to EDOM, ERANGE, ENOSYS and EINTR.
* src/c++17/fs_ops.cc (fs::current_path) [__AVR__]: Do not check
for ENOENT etc. in switch.
(fs::remove_all) [__AVR__]: Likewise.
* src/filesystem/ops-common.h [__AVR__]: Do not use POSIX open,
close etc.
(cherry picked from commit 2d2e163d12f64a5e68f9e0381751ed9d5d6d3617)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/104883] <system_error> should define all std::errc enumerators
2022-03-11 15:20 [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators redi at gcc dot gnu.org
` (4 preceding siblings ...)
2023-02-02 9:34 ` cvs-commit at gcc dot gnu.org
@ 2023-03-16 16:51 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-16 16:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104883
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:c86ac1a463f97554b1df9ef8a3e18573ef115e35
commit r11-10578-gc86ac1a463f97554b1df9ef8a3e18573ef115e35
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Jan 31 22:16:31 2023 +0000
libstdc++: Fix build failures for avr
The avr-libc <errno.h> does not define EOVERFLOW, which means that
std::errc::value_too_large is not defined, and so <charconv> cannot be
compiled. Define value_too_large for avr with a value that does not
clash with any that is defined in <errno.h>. This is a kluge to fix
bootstrap for avr; it can be removed after PR libstdc++/104883 is
resolved.
The avr-libc <errno.h> fails to meet the C and POSIX requirements that
each error macro has a distinct integral value, and is usable in #if
directives. Add a special case for avr to system_error.cc so that only
the valid errors are recognized. Also disable the errno checks in
std::filesystem::remove_all that assume a meaningful value for errno.
On avr-libc <unistd.h> exists but does not define the POSIX functions
needed by std::filesystem, so _GLIBCXX_HAVE_UNISTD_H is not sufficient
to check for basic POSIX APIs. Check !defined __AVR__ as well as
_GLIBCXX_HAVE_UNISTD_H before using those functions. This is a kluge and
we should really have a specific macro that says the required functions
are available.
libstdc++-v3/ChangeLog:
* config/os/generic/error_constants.h (errc::value_too_large)
[__AVR__]: Define.
* src/c++11/system_error.cc
(system_category::default_error_condition) [__AVR__]: Only match
recognize values equal to EDOM, ERANGE, ENOSYS and EINTR.
* src/c++17/fs_ops.cc (fs::current_path) [__AVR__]: Do not use
getcwd.
* src/filesystem/ops-common.h [__AVR__]: Do not use POSIX open,
close etc.
(cherry picked from commit 2d2e163d12f64a5e68f9e0381751ed9d5d6d3617)
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-03-16 16:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 15:20 [Bug libstdc++/104883] New: <system_error> should define all std::errc enumerators redi at gcc dot gnu.org
2022-09-22 10:47 ` [Bug libstdc++/104883] " redi at gcc dot gnu.org
2022-09-22 21:59 ` redi at gcc dot gnu.org
2023-02-01 21:07 ` cvs-commit at gcc dot gnu.org
2023-02-01 21:23 ` redi at gcc dot gnu.org
2023-02-02 9:34 ` cvs-commit at gcc dot gnu.org
2023-03-16 16:51 ` cvs-commit at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).