diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-12 13:35:22 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-12 13:35:22 +0000 |
commit | b89d59056f65962610b41f5bfb38abc59875370c (patch) | |
tree | 665ac82091f6e9d408cfc6f83ab9733db92b1094 /libstdc++-v3 | |
parent | 0803715f8776c3e990629c1ea158e328e1021a72 (diff) | |
download | gcc-b89d59056f65962610b41f5bfb38abc59875370c.tar.gz |
2010-10-12 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/random.tcc (piecewise_linear_distribution<>::
operator()): Don't crash when the dist is default-constructed.
* testsuite/26_numerics/random/piecewise_linear_distribution/
operators/call-default.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165379 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/random.tcc | 3 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/call-default.cc | 41 |
3 files changed, 51 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 14d834e4a58..b6bd2ef998d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2010-10-12 Paolo Carlini <paolo.carlini@oracle.com> + + * include/bits/random.tcc (piecewise_linear_distribution<>:: + operator()): Don't crash when the dist is default-constructed. + * testsuite/26_numerics/random/piecewise_linear_distribution/ + operators/call-default.cc: New. + 2010-10-11 Jonathan Wakely <jwakely.gcc@gmail.com> * testsuite/23_containers/bitset/cons/2.cc: Tweak. diff --git a/libstdc++-v3/include/bits/random.tcc b/libstdc++-v3/include/bits/random.tcc index 9312038f834..d360b41c9b6 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -2623,6 +2623,9 @@ namespace std __aurng(__urng); const double __p = __aurng(); + if (__param._M_m.empty()) + return __p; + auto __pos = std::lower_bound(__param._M_cp.begin(), __param._M_cp.end(), __p); const size_t __i = __pos - __param._M_cp.begin(); diff --git a/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/call-default.cc b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/call-default.cc new file mode 100644 index 00000000000..426c4d83711 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/random/piecewise_linear_distribution/operators/call-default.cc @@ -0,0 +1,41 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-10-12 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 26.5.8.5.3 Class template piecewise_linear_distribution +// [rand.dist.samp.plinear] + +#include <random> + +void +test01() +{ + std::piecewise_linear_distribution<> u; + std::minstd_rand0 rng; + + u(rng); +} + +int main() +{ + test01(); + return 0; +} |