From patchwork Tue Oct 12 13:37:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 67576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 411CDB70DF for ; Wed, 13 Oct 2010 00:37:31 +1100 (EST) Received: (qmail 7195 invoked by alias); 12 Oct 2010 13:37:28 -0000 Received: (qmail 7137 invoked by uid 22791); 12 Oct 2010 13:37:28 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp1.tin.it (HELO vsmtp1.tin.it) (212.216.176.141) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Oct 2010 13:37:15 +0000 Received: from [192.168.0.4] (79.17.189.97) by vsmtp1.tin.it (8.0.022) id 4B9917F01300A74E; Tue, 12 Oct 2010 15:37:12 +0200 Message-ID: <4CB46488.7060103@oracle.com> Date: Tue, 12 Oct 2010 15:37:12 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.12) Gecko/20100914 SUSE/3.0.8 Thunderbird/3.0.8 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Fix default-constructed piecewise_linear_distribution X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, tested x86_64-linux, will go in 4_5-branch too. Paolo. ////////////////////////////// 2010-10-12 Paolo Carlini * 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. Index: include/bits/random.tcc =================================================================== --- include/bits/random.tcc (revision 165351) +++ include/bits/random.tcc (working copy) @@ -2623,6 +2623,9 @@ __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(); Index: testsuite/26_numerics/random/piecewise_linear_distribution/operators/call-default.cc =================================================================== --- testsuite/26_numerics/random/piecewise_linear_distribution/operators/call-default.cc (revision 0) +++ testsuite/26_numerics/random/piecewise_linear_distribution/operators/call-default.cc (revision 0) @@ -0,0 +1,41 @@ +// { dg-options "-std=c++0x" } +// { dg-require-cstdint "" } +// +// 2010-10-12 Paolo Carlini +// +// 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 +// . + +// 26.5.8.5.3 Class template piecewise_linear_distribution +// [rand.dist.samp.plinear] + +#include + +void +test01() +{ + std::piecewise_linear_distribution<> u; + std::minstd_rand0 rng; + + u(rng); +} + +int main() +{ + test01(); + return 0; +}