mirror of git://gcc.gnu.org/git/gcc.git
libstdc++: Make std::random_device throw more std::system_error [PR105081]
In r14-289-gf9412cedd6c0e7 I made the std::random_device constructor throw std::system_error for unrecognized tokens. But it still throws std::runtime_error for a token such as "rdseed" that is recognized but not supported at runtime by the CPU the program is running on. With this change we throw std::system_error for those cases too. This fixes the following failures on Intel CPUs withour rdseed support: FAIL: 26_numerics/random/random_device/94087.cc execution test FAIL: 26_numerics/random/random_device/cons/token.cc execution test FAIL: 26_numerics/random/random_device/entropy.cc execution test libstdc++-v3/ChangeLog: PR libstdc++/105081 * src/c++11/random.cc (random_device::_M_init): Throw std::system_error when the requested device is a valid token but not available at runtime.
This commit is contained in:
parent
ca15abc0ff
commit
d6a6a4ea08
|
@ -373,6 +373,15 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
"(const std::string&):"
|
"(const std::string&):"
|
||||||
" unsupported token"));
|
" unsupported token"));
|
||||||
|
|
||||||
|
#if defined ENOSYS
|
||||||
|
const int unsupported = ENOSYS;
|
||||||
|
#elif defined ENOTSUP
|
||||||
|
const int unsupported = ENOTSUP;
|
||||||
|
#else
|
||||||
|
const int unsupported = 0;
|
||||||
|
#endif
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
#ifdef _GLIBCXX_USE_CRT_RAND_S
|
#ifdef _GLIBCXX_USE_CRT_RAND_S
|
||||||
if (which & rand_s)
|
if (which & rand_s)
|
||||||
{
|
{
|
||||||
|
@ -407,6 +416,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
err = unsupported;
|
||||||
}
|
}
|
||||||
#endif // USE_RDSEED
|
#endif // USE_RDSEED
|
||||||
|
|
||||||
|
@ -427,6 +437,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
err = unsupported;
|
||||||
}
|
}
|
||||||
#endif // USE_RDRAND
|
#endif // USE_RDRAND
|
||||||
|
|
||||||
|
@ -438,6 +449,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
_M_func = &__ppc_darn;
|
_M_func = &__ppc_darn;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
err = unsupported;
|
||||||
}
|
}
|
||||||
#endif // USE_DARN
|
#endif // USE_DARN
|
||||||
|
|
||||||
|
@ -458,6 +470,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
_M_func = &__libc_getentropy;
|
_M_func = &__libc_getentropy;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
err = unsupported;
|
||||||
}
|
}
|
||||||
#endif // _GLIBCXX_HAVE_GETENTROPY
|
#endif // _GLIBCXX_HAVE_GETENTROPY
|
||||||
|
|
||||||
|
@ -477,6 +490,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
if (_M_file)
|
if (_M_file)
|
||||||
return;
|
return;
|
||||||
#endif // USE_POSIX_FILE_IO
|
#endif // USE_POSIX_FILE_IO
|
||||||
|
err = errno;
|
||||||
}
|
}
|
||||||
#endif // _GLIBCXX_USE_DEV_RANDOM
|
#endif // _GLIBCXX_USE_DEV_RANDOM
|
||||||
|
|
||||||
|
@ -493,9 +507,12 @@ namespace std _GLIBCXX_VISIBILITY(default)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::__throw_runtime_error(
|
auto msg = __N("random_device::random_device(const std::string&):"
|
||||||
__N("random_device::random_device(const std::string&):"
|
" device not available");
|
||||||
" device not available"));
|
if (err)
|
||||||
|
std::__throw_syserr(err, msg);
|
||||||
|
else
|
||||||
|
std::__throw_runtime_error(msg);
|
||||||
#endif // USE_MT19937
|
#endif // USE_MT19937
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue