aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Smith-Rowland <3dw4rd@verizon.net>2014-07-29 14:56:45 +0000
committerEdward Smith-Rowland <emsr@gcc.gnu.org>2014-07-29 14:56:45 +0000
commit1c4ff014fe1f6b440b4df75ca6f419ebc00fcac0 (patch)
treec98e05a6bf49ab42d191c28ae725ebc36e2debb1
parentf3691f465e062f2380c0d9a6018951030fc8a2a3 (diff)
downloadgcc-1c4ff014fe1f6b440b4df75ca6f419ebc00fcac0.zip
gcc-1c4ff014fe1f6b440b4df75ca6f419ebc00fcac0.tar.gz
gcc-1c4ff014fe1f6b440b4df75ca6f419ebc00fcac0.tar.bz2
PR libstdc++/60037 - SIGFPE in std::generate_canonical<unsigned int...>
2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net> PR libstdc++/60037 - SIGFPE in std::generate_canonical<unsigned int...> * include/bits/random.h (_Adaptor): static_assert for non floating-point result type. * include/bits/random.tcc (generate_canonical): Ditto. * include/ext/random.tcc (hypergeometric_distribution::operator()): Use double as a rng result type. * testsuite/26_numerics/random/pr60037-neg.cc: New. * testsuite/ext/random/hypergeometric_distribution/pr60037.cc: New. From-SVN: r213207
-rw-r--r--libstdc++-v3/ChangeLog11
-rw-r--r--libstdc++-v3/include/bits/random.h2
-rw-r--r--libstdc++-v3/include/bits/random.tcc3
-rw-r--r--libstdc++-v3/include/ext/random.tcc2
-rw-r--r--libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc15
-rw-r--r--libstdc++-v3/testsuite/ext/random/hypergeometric_distribution/pr60037.cc23
6 files changed, 55 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 58febfb..4a7ee07 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,14 @@
+2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
+
+ PR libstdc++/60037 - SIGFPE in std::generate_canonical<unsigned int...>
+ * include/bits/random.h (_Adaptor): static_assert for non floating-point
+ result type.
+ * include/bits/random.tcc (generate_canonical): Ditto.
+ * include/ext/random.tcc (hypergeometric_distribution::operator()):
+ Use double as a rng result type.
+ * testsuite/26_numerics/random/pr60037-neg.cc: New.
+ * testsuite/ext/random/hypergeometric_distribution/pr60037.cc: New.
+
2014-07-25 Uros Bizjak <ubizjak@gmail.com>
* config/abi/post/alpha-linux-gnu/baseline_symbols.txt: Update.
diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h
index a466a45..774f726 100644
--- a/libstdc++-v3/include/bits/random.h
+++ b/libstdc++-v3/include/bits/random.h
@@ -164,6 +164,8 @@ _GLIBCXX_END_NAMESPACE_VERSION
template<typename _Engine, typename _DInputType>
struct _Adaptor
{
+ static_assert(std::is_floating_point<_DInputType>::value,
+ "template argument not a floating point type");
public:
_Adaptor(_Engine& __g)
diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc
index 0eda287..8849ee9 100644
--- a/libstdc++-v3/include/bits/random.tcc
+++ b/libstdc++-v3/include/bits/random.tcc
@@ -3463,6 +3463,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_RealType
generate_canonical(_UniformRandomNumberGenerator& __urng)
{
+ static_assert(std::is_floating_point<_RealType>::value,
+ "template argument not a floating point type");
+
const size_t __b
= std::min(static_cast<size_t>(std::numeric_limits<_RealType>::digits),
__bits);
diff --git a/libstdc++-v3/include/ext/random.tcc b/libstdc++-v3/include/ext/random.tcc
index 432865c..05361d8 100644
--- a/libstdc++-v3/include/ext/random.tcc
+++ b/libstdc++-v3/include/ext/random.tcc
@@ -1355,7 +1355,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __param)
{
- std::__detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
+ std::__detail::_Adaptor<_UniformRandomNumberGenerator, double>
__aurng(__urng);
result_type __a = __param.successful_size();
diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
new file mode 100644
index 0000000..11d5539
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+#include <random>
+
+std::mt19937 urng;
+
+std::__detail::_Adaptor<std::mt19937, unsigned long> aurng(urng);
+
+auto x = std::generate_canonical<std::size_t,
+ std::numeric_limits<std::size_t>::digits>(urng);
+
+// { dg-error "static assertion failed: template argument not a floating point type" "" { target *-*-* } 167 }
+
+// { dg-error "static assertion failed: template argument not a floating point type" "" { target *-*-* } 3466 }
diff --git a/libstdc++-v3/testsuite/ext/random/hypergeometric_distribution/pr60037.cc b/libstdc++-v3/testsuite/ext/random/hypergeometric_distribution/pr60037.cc
new file mode 100644
index 0000000..d3088a6
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/random/hypergeometric_distribution/pr60037.cc
@@ -0,0 +1,23 @@
+// { dg-options "-std=gnu++11 -O0" }
+// { dg-require-cstdint "" }
+// { dg-require-cmath "" }
+
+#include <ext/random>
+#include <functional>
+
+void
+hyperplot(unsigned int N, unsigned int K, unsigned int n)
+{
+ std::mt19937 re; // the default engine
+ __gnu_cxx::hypergeometric_distribution<> hd(N, K, n);
+ auto gen = std::bind(hd, re);
+ gen();
+}
+
+int
+main()
+{
+ hyperplot(15, 3, 2);
+ hyperplot(500, 50, 30);
+ hyperplot(100, 20, 5);
+}