From ce4674f2a6ac6bb7b8926076adf92694443f3f1b Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 17 Feb 2010 12:18:54 +0000 Subject: [PATCH] limits: Implement resolution of DR 559 (CD1) in C++0x mode. 2010-02-17 Paolo Carlini * include/std/limits: Implement resolution of DR 559 (CD1) in C++0x mode. * testsuite/18_support/numeric_limits/dr559.cc: New. From-SVN: r156830 --- libstdc++-v3/ChangeLog | 6 ++ libstdc++-v3/include/std/limits | 24 ++++- .../18_support/numeric_limits/dr559.cc | 100 ++++++++++++++++++ 3 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/18_support/numeric_limits/dr559.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 99e78f503aa..5eff61ac963 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2010-02-17 Paolo Carlini + + * include/std/limits: Implement resolution of DR 559 (CD1) in + C++0x mode. + * testsuite/18_support/numeric_limits/dr559.cc: New. + 2010-02-16 Benjamin Kosnik * src/ios_locale.cc: Fixes for -pedantic. diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits index 76a53222893..a633d78bf03 100644 --- a/libstdc++-v3/include/std/limits +++ b/libstdc++-v3/include/std/limits @@ -45,10 +45,10 @@ // // The numeric_limits<> traits document implementation-defined aspects // of fundamental arithmetic data types (integers and floating points). -// From Standard C++ point of view, there are 13 such types: +// From Standard C++ point of view, there are 14 such types: // * integers // bool (1) -// char, signed char, unsigned char (3) +// char, signed char, unsigned char, wchar_t (4) // short, unsigned short (2) // int, unsigned (2) // long, unsigned long (2) @@ -62,7 +62,7 @@ // * integer // long long, unsigned long long (2) // -// which brings us to 15 fundamental arithmetic data types in GNU C++. +// which brings us to 16 fundamental arithmetic data types in GNU C++. // // // Since a numeric_limits<> is a bit tricky to get right, we rely on @@ -302,8 +302,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) static _Tp denorm_min() throw() { return static_cast<_Tp>(0); } }; - // Now there follow 15 explicit specializations. Yes, 15. Make sure - // you get the count right. +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + struct numeric_limits + : public numeric_limits<_Tp> { }; + + template + struct numeric_limits + : public numeric_limits<_Tp> { }; + + template + struct numeric_limits + : public numeric_limits<_Tp> { }; +#endif + + // Now there follow 16 explicit specializations. Yes, 16. Make sure + // you get the count right. (18 in c++0x mode) /// numeric_limits specialization. template<> diff --git a/libstdc++-v3/testsuite/18_support/numeric_limits/dr559.cc b/libstdc++-v3/testsuite/18_support/numeric_limits/dr559.cc new file mode 100644 index 00000000000..f541faae583 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/numeric_limits/dr559.cc @@ -0,0 +1,100 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-02-17 Paolo Carlini +// +// Copyright (C) 2010 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 +#include + +template + void do_test_aux() + { + bool test __attribute__((unused)) = true; + typedef std::numeric_limits cv_limits; + typedef std::numeric_limits::type> limits; + + VERIFY( cv_limits::is_specialized == limits::is_specialized ); + VERIFY( cv_limits::min() == limits::min() ); + VERIFY( cv_limits::max() == limits::max() ); + VERIFY( cv_limits::digits == limits::digits ); + VERIFY( cv_limits::digits10 == limits::digits10 ); + VERIFY( cv_limits::is_signed == limits::is_signed ); + VERIFY( cv_limits::is_integer == limits::is_integer ); + VERIFY( cv_limits::is_exact == limits::is_exact ); + VERIFY( cv_limits::radix == limits::radix ); + VERIFY( cv_limits::epsilon() == limits::epsilon() ); + VERIFY( cv_limits::round_error() == limits::round_error() ); + VERIFY( cv_limits::min_exponent == limits::min_exponent ); + VERIFY( cv_limits::min_exponent10 == limits::min_exponent10 ); + VERIFY( cv_limits::max_exponent == limits::max_exponent ); + VERIFY( cv_limits::max_exponent10 == limits::max_exponent10 ); + VERIFY( cv_limits::has_infinity == limits::has_infinity ); + VERIFY( cv_limits::has_quiet_NaN == limits::has_quiet_NaN ); + VERIFY( cv_limits::has_signaling_NaN == limits::has_signaling_NaN ); + VERIFY( cv_limits::has_denorm == limits::has_denorm ); + VERIFY( cv_limits::has_denorm_loss == limits::has_denorm_loss ); + VERIFY( cv_limits::infinity() == limits::infinity() ); + if (!std::is_floating_point::value) + { + VERIFY( cv_limits::quiet_NaN() == limits::quiet_NaN() ); + VERIFY( cv_limits::signaling_NaN() == limits::signaling_NaN() ); + } + VERIFY( cv_limits::denorm_min() == limits::denorm_min() ); + VERIFY( cv_limits::is_iec559 == limits::is_iec559 ); + VERIFY( cv_limits::is_bounded == limits::is_bounded ); + VERIFY( cv_limits::is_modulo == limits::is_modulo ); + VERIFY( cv_limits::traps == limits::traps ); + VERIFY( cv_limits::tinyness_before == limits::tinyness_before ); + VERIFY( cv_limits::round_style == limits::round_style ); + } + +template + void + do_test() + { + do_test_aux(); + do_test_aux(); + do_test_aux(); + do_test_aux(); + } + +// DR 559. +int main() +{ + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + do_test(); + return 0; +}