re PR libstdc++/53840 ([C++11] DR 921. Rational Arithmetic should use template aliases)
2012-07-03 Paolo Carlini <paolo.carlini@oracle.com> PR libstdc++/53840 * include/std/ratio (ratio_multiply, ratio_divide, ratio_add, ratio_subtract): Use template aliases. * include/std/chrono (duration<>::duration(const duration<>&), duration_cast): Adjust. * testsuite/20_util/ratio/operations/53840.cc: New. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Likewise. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise. * testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Likewise. From-SVN: r189239
This commit is contained in:
parent
f5d306802c
commit
c128d2031e
8 changed files with 83 additions and 33 deletions
|
@ -1,3 +1,16 @@
|
|||
2012-07-03 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
PR libstdc++/53840
|
||||
* include/std/ratio (ratio_multiply, ratio_divide, ratio_add,
|
||||
ratio_subtract): Use template aliases.
|
||||
* include/std/chrono (duration<>::duration(const duration<>&),
|
||||
duration_cast): Adjust.
|
||||
* testsuite/20_util/ratio/operations/53840.cc: New.
|
||||
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust.
|
||||
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Likewise.
|
||||
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise.
|
||||
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Likewise.
|
||||
|
||||
2012-07-02 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
Revert:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// <chrono> -*- C++ -*-
|
||||
|
||||
// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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
|
||||
|
@ -174,8 +174,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
|
|||
{
|
||||
typedef typename _ToDur::period __to_period;
|
||||
typedef typename _ToDur::rep __to_rep;
|
||||
typedef ratio_divide<_Period, __to_period> __r_div;
|
||||
typedef typename __r_div::type __cf;
|
||||
typedef ratio_divide<_Period, __to_period> __cf;
|
||||
typedef typename common_type<__to_rep, _Rep, intmax_t>::type
|
||||
__cr;
|
||||
typedef __duration_cast_impl<_ToDur, __cf, __cr,
|
||||
|
@ -242,7 +241,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
|
|||
|
||||
template<typename _Rep2, typename _Period2, typename = typename
|
||||
enable_if<treat_as_floating_point<rep>::value
|
||||
|| (ratio_divide<_Period2, period>::type::den == 1
|
||||
|| (ratio_divide<_Period2, period>::den == 1
|
||||
&& !treat_as_floating_point<_Rep2>::value)>::type>
|
||||
constexpr duration(const duration<_Rep2, _Period2>& __d)
|
||||
: __r(duration_cast<duration>(__d).count()) { }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// ratio -*- C++ -*-
|
||||
|
||||
// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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
|
||||
|
@ -282,9 +282,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
template<intmax_t _Num, intmax_t _Den>
|
||||
constexpr intmax_t ratio<_Num, _Den>::den;
|
||||
|
||||
/// ratio_multiply
|
||||
template<typename _R1, typename _R2>
|
||||
struct ratio_multiply
|
||||
struct __ratio_multiply
|
||||
{
|
||||
private:
|
||||
static const intmax_t __gcd1 =
|
||||
|
@ -304,18 +303,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
};
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_multiply<_R1, _R2>::num;
|
||||
constexpr intmax_t __ratio_multiply<_R1, _R2>::num;
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_multiply<_R1, _R2>::den;
|
||||
constexpr intmax_t __ratio_multiply<_R1, _R2>::den;
|
||||
|
||||
/// ratio_divide
|
||||
/// ratio_multiply
|
||||
template<typename _R1, typename _R2>
|
||||
struct ratio_divide
|
||||
using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type;
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
struct __ratio_divide
|
||||
{
|
||||
static_assert(_R2::num != 0, "division by 0");
|
||||
|
||||
typedef typename ratio_multiply<
|
||||
typedef typename __ratio_multiply<
|
||||
_R1,
|
||||
ratio<_R2::den, _R2::num>>::type type;
|
||||
|
||||
|
@ -324,10 +326,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
};
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_divide<_R1, _R2>::num;
|
||||
constexpr intmax_t __ratio_divide<_R1, _R2>::num;
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_divide<_R1, _R2>::den;
|
||||
constexpr intmax_t __ratio_divide<_R1, _R2>::den;
|
||||
|
||||
/// ratio_divide
|
||||
template<typename _R1, typename _R2>
|
||||
using ratio_divide = typename __ratio_divide<_R1, _R2>::type;
|
||||
|
||||
/// ratio_equal
|
||||
template<typename _R1, typename _R2>
|
||||
|
@ -464,9 +470,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
typedef ratio<__n_final::__quot_lo, __d_final::__lo> type;
|
||||
};
|
||||
|
||||
/// ratio_add
|
||||
template<typename _R1, typename _R2>
|
||||
struct ratio_add
|
||||
struct __ratio_add
|
||||
{
|
||||
typedef typename __ratio_add_impl<_R1, _R2>::type type;
|
||||
static constexpr intmax_t num = type::num;
|
||||
|
@ -474,16 +479,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
};
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_add<_R1, _R2>::num;
|
||||
constexpr intmax_t __ratio_add<_R1, _R2>::num;
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_add<_R1, _R2>::den;
|
||||
constexpr intmax_t __ratio_add<_R1, _R2>::den;
|
||||
|
||||
/// ratio_subtract
|
||||
/// ratio_add
|
||||
template<typename _R1, typename _R2>
|
||||
struct ratio_subtract
|
||||
using ratio_add = typename __ratio_add<_R1, _R2>::type;
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
struct __ratio_subtract
|
||||
{
|
||||
typedef typename ratio_add<
|
||||
typedef typename __ratio_add<
|
||||
_R1,
|
||||
ratio<-_R2::num, _R2::den>>::type type;
|
||||
|
||||
|
@ -492,11 +500,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
};
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_subtract<_R1, _R2>::num;
|
||||
constexpr intmax_t __ratio_subtract<_R1, _R2>::num;
|
||||
|
||||
template<typename _R1, typename _R2>
|
||||
constexpr intmax_t ratio_subtract<_R1, _R2>::den;
|
||||
constexpr intmax_t __ratio_subtract<_R1, _R2>::den;
|
||||
|
||||
/// ratio_subtract
|
||||
template<typename _R1, typename _R2>
|
||||
using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type;
|
||||
|
||||
|
||||
typedef ratio<1, 1000000000000000000> atto;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// { dg-require-cstdint "" }
|
||||
// 2008-07-31 Chris Fairles <chris.fairles@gmail.com>
|
||||
|
||||
// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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
|
||||
|
@ -31,5 +31,5 @@ void test01()
|
|||
test_type d;
|
||||
}
|
||||
|
||||
// { dg-error "rep cannot be a duration" "" { target *-*-* } 226 }
|
||||
// { dg-error "rep cannot be a duration" "" { target *-*-* } 225 }
|
||||
// { dg-error "required from here" "" { target *-*-* } 31 }
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// { dg-require-cstdint "" }
|
||||
// 2008-07-31 Chris Fairles <chris.fairles@gmail.com>
|
||||
|
||||
// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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
|
||||
|
@ -32,5 +32,5 @@ void test01()
|
|||
test_type d; // { dg-error "required from here" }
|
||||
}
|
||||
|
||||
// { dg-error "must be a specialization of ratio" "" { target *-*-* } 227 }
|
||||
// { dg-error "must be a specialization of ratio" "" { target *-*-* } 226 }
|
||||
// { dg-prune-output "not a member" }
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// { dg-require-cstdint "" }
|
||||
// 2008-07-31 Chris Fairles <chris.fairles@gmail.com>
|
||||
|
||||
// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2008, 2009, 2010, 2011, 2012 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
|
||||
|
@ -33,5 +33,5 @@ void test01()
|
|||
test_type d;
|
||||
}
|
||||
|
||||
// { dg-error "period must be positive" "" { target *-*-* } 229 }
|
||||
// { dg-error "period must be positive" "" { target *-*-* } 228 }
|
||||
// { dg-error "required from here" "" { target *-*-* } 33 }
|
||||
|
|
27
libstdc++-v3/testsuite/20_util/ratio/operations/53840.cc
Normal file
27
libstdc++-v3/testsuite/20_util/ratio/operations/53840.cc
Normal file
|
@ -0,0 +1,27 @@
|
|||
// { dg-options "-std=gnu++0x" }
|
||||
// { dg-require-cstdint "" }
|
||||
// { dg-do compile }
|
||||
|
||||
// Copyright (C) 2012 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
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <chrono>
|
||||
|
||||
std::chrono::duration<long, std::ratio_divide<std::kilo, std::milli>> d1;
|
||||
std::chrono::duration<long, std::ratio_multiply<std::kilo, std::milli>> d2;
|
||||
std::chrono::duration<long, std::ratio_add<std::kilo, std::milli>> d3;
|
||||
std::chrono::duration<long, std::ratio_subtract<std::kilo, std::milli>> d4;
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
// 2008-07-03 Chris Fairles <chris.fairles@gmail.com>
|
||||
|
||||
// Copyright (C) 2008, 2009, 2011 Free Software Foundation
|
||||
// Copyright (C) 2008, 2009, 2011, 2012 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
|
||||
|
@ -40,9 +40,9 @@ test02()
|
|||
}
|
||||
|
||||
// { dg-error "required from here" "" { target *-*-* } 29 }
|
||||
// { dg-error "required from here" "" { target *-*-* } 36 }
|
||||
// { dg-error "required from here" "" { target *-*-* } 38 }
|
||||
// { dg-error "overflow in addition" "" { target *-*-* } 429 }
|
||||
// { dg-error "expected initializer" "" { target *-*-* } 36 }
|
||||
// { dg-error "expected initializer" "" { target *-*-* } 38 }
|
||||
// { dg-error "overflow in addition" "" { target *-*-* } 435 }
|
||||
// { dg-error "overflow in multiplication" "" { target *-*-* } 97 }
|
||||
// { dg-error "overflow in multiplication" "" { target *-*-* } 99 }
|
||||
// { dg-error "overflow in multiplication" "" { target *-*-* } 101 }
|
||||
|
|
Loading…
Add table
Reference in a new issue