From patchwork Mon Feb 28 16:48:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 84848 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 9604DB7127 for ; Tue, 1 Mar 2011 03:48:38 +1100 (EST) Received: (qmail 20130 invoked by alias); 28 Feb 2011 16:48:36 -0000 Received: (qmail 20104 invoked by uid 22791); 28 Feb 2011 16:48:32 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from smtp206.alice.it (HELO smtp206.alice.it) (82.57.200.102) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Feb 2011 16:48:24 +0000 Received: from [192.168.1.4] (79.47.194.33) by smtp206.alice.it (8.5.124.08) id 4D49918D02221725; Mon, 28 Feb 2011 17:48:19 +0100 Message-ID: <4D6BD1D3.3030909@oracle.com> Date: Mon, 28 Feb 2011 17:48:19 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Fix libstdc++/42622 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 multilib, committed to mainline. Paolo. ////////////////////// 2011-02-28 Paolo Carlini * testsuite/20_util/ratio/comparisons/comp3.cc: New. 2011-02-28 Marc Glisse PR libstdc++/42622 * include/std/ratio (ratio_less): Reimplement to never overflow. * testsuite/20_util/ratio/comparisons/comp2.cc: Extend. Index: testsuite/20_util/ratio/comparisons/comp2.cc =================================================================== --- testsuite/20_util/ratio/comparisons/comp2.cc (revision 170558) +++ testsuite/20_util/ratio/comparisons/comp2.cc (working copy) @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // { dg-require-cstdint "" } -// Copyright (C) 2008, 2009, 2010 Free Software Foundation +// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation // // 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 @@ -48,6 +48,9 @@ VERIFY( (std::ratio_less, std::ratio<-M, M - 2>>::value == 0) ); + + VERIFY( (std::ratio_less, + std::ratio>::value == 1) ); } int main() Index: testsuite/20_util/ratio/comparisons/comp3.cc =================================================================== --- testsuite/20_util/ratio/comparisons/comp3.cc (revision 0) +++ testsuite/20_util/ratio/comparisons/comp3.cc (revision 0) @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } + +// 2011-02-28 Paolo Carlini + +// Copyright (C) 2011 Free Software Foundation +// +// 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 +// . + +#include +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( (std::ratio_less, + std::ratio<59, 29129>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<4751, 13>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<25733, 25741>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<673, 773>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<17891, 32099>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<18457, 19571>>::value == 1) ); + + VERIFY( (std::ratio_less, + std::ratio<60, 29130>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<4752, 14>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<25732, 25742>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<674, 774>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<17892, 32100>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<18458, 19572>>::value == 1) ); + + VERIFY( (std::ratio_less, + std::ratio<58, 29128>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<4750, 12>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<25734, 25740>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<672, 772>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<17890, 32102>>::value == 1) ); + VERIFY( (std::ratio_less, + std::ratio<18456, 19570>>::value == 1) ); +} + +int main() +{ + test01(); + return 0; +} Index: include/std/ratio =================================================================== --- include/std/ratio (revision 170558) +++ include/std/ratio (working copy) @@ -1,6 +1,6 @@ // ratio -*- C++ -*- -// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -274,11 +274,44 @@ : integral_constant::value> { }; - template + // 0 <= _Ri < 1 + template + struct __ratio_less_impl_2; + + // _Ri > 0 + template struct __ratio_less_impl_1 - : integral_constant + : __ratio_less_impl_2, + ratio<_R2::num % _R2::den, _R2::den> >::type { }; + template + struct __ratio_less_impl_1<_R1, _R2, __q1, __q2, false> + : integral_constant + { }; + + template + struct __ratio_less_impl_2 + : __ratio_less_impl_1, + ratio<_R1::den, _R1::num> >::type + { }; + + template + struct __ratio_less_impl_2, _R2> + : integral_constant + { }; + + template + struct __ratio_less_impl_2<_R1, ratio<0, __d2> > + : integral_constant + { }; + + template + struct __ratio_less_impl_2, ratio<0, __d2> > + : integral_constant + { }; + template::value @@ -286,7 +319,7 @@ bool = (__static_sign<_R1::num>::value == -1 && __static_sign<_R2::num>::value == -1)> struct __ratio_less_impl - : __ratio_less_impl_1::type>::type + : __ratio_less_impl_1<_R1, _R2>::type { }; template @@ -296,7 +329,8 @@ template struct __ratio_less_impl<_R1, _R2, false, true> - : __ratio_less_impl_1::type>::type + : __ratio_less_impl_1, + ratio<-_R1::num, _R1::den> >::type { }; /// ratio_less