On Thu, 11 Jul 2024 at 14:23, Alexandre Oliva <ol...@adacore.com> wrote:
>
>
> Passing an arbitrary error number to strerror* functions doesn't seem
> to be portable; 19_diagnostics/system_error/cons-1.cc is hitting
> runtime errors in the block that attempts to instantiate a
> std:;system_error for error number 95.  The range of errno macros
> defined on this target doesn't reach 95.

The C standard is clear:

"Typically, the values for errnum come from errno, but strerror shall
map any value of type int to a message. "

And std::system_error doesn't limit the values that can be passed to
it either. So I'd prefer to keep testing with arbitrary int values,
because that *should* work.


>
> I'm changing the test to try to use a couple of select error codes,
> falling back to a lower error number if neither are present.
> Hopefully this doesn't change the nature of what is being tested for.

I think it does.

>
> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 targeting
> aarch64.  Ok to install?
>
>
> for  libstdc++-v3/ChangeLog
>
>         * testsuite/19_diagnostics/system_error/cons-1.cc: Use lower
>         error numbers, preferring some macro-defined ones.
> ---
>  .../19_diagnostics/system_error/cons-1.cc          |   14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc 
> b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc
> index 16aa960b2ee28..e227c67542411 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc
> @@ -37,8 +37,18 @@ int main()
>
>    // 2
>    {
> -    std::system_error err2(95, std::system_category(), s);
> -    VERIFY( err2.code() == std::error_code(95, std::system_category()) );
> +    int eno;
> +#if defined EOPNOTSUPP
> +    eno = EOPNOTSUPP;
> +#elif defined ENOSYS
> +    eno = ENOSYS;
> +#else
> +    // strerror (used to combine with the given message) may fail if
> +    // the error number is out of range for the system.
> +    eno = 42;
> +#endif
> +    std::system_error err2(eno, std::system_category(), s);
> +    VERIFY( err2.code() == std::error_code(eno, std::system_category()) );
>      VERIFY( std::string((err2.what(), s)).find(s) != std::string::npos );
>    }
>
>
> --
> Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
>    Free Software Activist                   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive
>

Reply via email to