[PATCH] [libstdc++] [testsuite] avoid arbitrary errno codes
Alexandre Oliva
oliva@adacore.com
Thu Jul 11 13:22:31 GMT 2024
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.
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
More information about the Libstdc++
mailing list