https://gcc.gnu.org/g:2f1f926425b4e3cd5e7e48b86e03bb3613b5aa54

commit 2f1f926425b4e3cd5e7e48b86e03bb3613b5aa54
Author: Alexandre Oliva <ol...@adacore.com>
Date:   Thu Jul 11 09:04:11 2024 -0300

    [libstdc++] [testsuite] avoid arbitrary errno codes
    
    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.
    
    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.
    
    
    for  libstdc++-v3/ChangeLog
    
            * testsuite/19_diagnostics/system_error/cons-1.cc: Use lower
            error numbers, preferring some macro-defined ones.

Diff:
---
 .../testsuite/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 16aa960b2ee2..e227c6754241 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 );
   }

Reply via email to