|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85441 - in branches/release: . boost libs libs/rational/test
From: dwalker07_at_[hidden]
Date: 2013-08-24 04:17:47
Author: dlwalker
Date: 2013-08-24 04:17:46 EDT (Sat, 24 Aug 2013)
New Revision: 85441
URL: http://svn.boost.org/trac/boost/changeset/85441
Log:
Merged [85417], [85418], and [85434] from trunk to release, fixing show-stoppers for Boost.Rational, like #5855 and a C++11 update for some test code
Properties modified:
branches/release/ (props changed)
branches/release/boost/ (props changed)
branches/release/libs/ (props changed)
Text files modified:
branches/release/boost/rational.hpp | 12 +++++----
branches/release/libs/rational/test/rational_test.cpp | 48 +++++++++++++++++++++++++++++++++++++--
2 files changed, 52 insertions(+), 8 deletions(-)
Modified: branches/release/boost/rational.hpp
==============================================================================
--- branches/release/boost/rational.hpp Fri Aug 23 22:32:49 2013 (r85440)
+++ branches/release/boost/rational.hpp 2013-08-24 04:17:46 EDT (Sat, 24 Aug 2013) (r85441)
@@ -28,9 +28,9 @@
// 31 Oct 06 Recoded both operator< to use round-to-negative-infinity
// divisions; the rational-value version now uses continued fraction
// expansion to avoid overflows, for bug #798357 (Daryle Walker)
-// 20 Oct 06 Fix operator bool_type for CW 8.3 (Joaquín M López Muñoz)
+// 20 Oct 06 Fix operator bool_type for CW 8.3 (JoaquÃn M López Muñoz)
// 18 Oct 06 Use EXPLICIT_TEMPLATE_TYPE helper macros from Boost.Config
-// (Joaquín M López Muñoz)
+// (JoaquÃn M López Muñoz)
// 27 Dec 05 Add Boolean conversion operator (Daryle Walker)
// 28 Sep 02 Use _left versions of operators from operators.hpp
// 05 Jul 01 Recode gcd(), avoiding std::swap (Helmut Zeisel)
@@ -389,9 +389,11 @@
// Determine relative order by expanding each value to its simple continued
// fraction representation using the Euclidian GCD algorithm.
- struct { int_type n, d, q, r; } ts = { this->num, this->den, this->num /
- this->den, this->num % this->den }, rs = { r.num, r.den, r.num / r.den,
- r.num % r.den };
+ struct { int_type n, d, q, r; }
+ ts = { this->num, this->den, static_cast<int_type>(this->num / this->den),
+ static_cast<int_type>(this->num % this->den) },
+ rs = { r.num, r.den, static_cast<int_type>(r.num / r.den),
+ static_cast<int_type>(r.num % r.den) };
unsigned reverse = 0u;
// Normalize negative moduli by repeatedly adding the (positive) denominator
Modified: branches/release/libs/rational/test/rational_test.cpp
==============================================================================
--- branches/release/libs/rational/test/rational_test.cpp Fri Aug 23 22:32:49 2013 (r85440)
+++ branches/release/libs/rational/test/rational_test.cpp 2013-08-24 04:17:46 EDT (Sat, 24 Aug 2013) (r85441)
@@ -14,12 +14,15 @@
*/
// Revision History
+// 23 Aug 13 Add bug-test of narrowing conversions during order comparison;
+// spell logical-negation in it as "!" because MSVC won't accept
+// "not" (Daryle Walker)
// 05 Nov 06 Add testing of zero-valued denominators & divisors; casting with
// types that are not implicitly convertible (Daryle Walker)
// 04 Nov 06 Resolve GCD issue with depreciation (Daryle Walker)
// 02 Nov 06 Add testing for operator<(int_type) w/ unsigneds (Daryle Walker)
// 31 Oct 06 Add testing for operator<(rational) overflow (Daryle Walker)
-// 18 Oct 06 Various fixes for old compilers (Joaquín M López Muñoz)
+// 18 Oct 06 Various fixes for old compilers (JoaquÃn M López Muñoz)
// 27 Dec 05 Add testing for Boolean conversion operator (Daryle Walker)
// 24 Dec 05 Change code to use Boost.Test (Daryle Walker)
// 04 Mar 01 Patches for Intel C++ and GCC (David Abrahams)
@@ -230,9 +233,12 @@
static MyInt min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return (limits_type::min)(); }
static MyInt max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return (limits_type::max)(); }
+ static MyInt lowest() throw() { return min BOOST_PREVENT_MACRO_SUBSTITUTION
+ (); } // C++11
static const int digits = limits_type::digits;
static const int digits10 = limits_type::digits10;
+ static const int max_digits10 = 0; // C++11
static const bool is_signed = limits_type::is_signed;
static const bool is_integer = limits_type::is_integer;
static const bool is_exact = limits_type::is_exact;
@@ -276,9 +282,12 @@
static MyOverflowingUnsigned min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return (limits_type::min)(); }
static MyOverflowingUnsigned max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return (limits_type::max)(); }
+ static MyOverflowingUnsigned lowest() throw()
+ { return min BOOST_PREVENT_MACRO_SUBSTITUTION (); } // C++11
static const int digits = limits_type::digits;
static const int digits10 = limits_type::digits10;
+ static const int max_digits10 = 0; // C++11
static const bool is_signed = limits_type::is_signed;
static const bool is_integer = limits_type::is_integer;
static const bool is_exact = limits_type::is_exact;
@@ -348,7 +357,7 @@
<< sizeof( rational_type ) << "\n\n";
cout << "Implementation has "
- << (
+ << (
(sizeof( rational_type ) > 2u * sizeof( int_type ))
? "included padding bytes"
: "minimal size"
@@ -792,7 +801,7 @@
BOOST_AUTO_TEST_CASE_TEMPLATE( rational_output_test, T, all_signed_test_types )
{
std::ostringstream oss;
-
+
oss << boost::rational<T>( 44, 14 );
BOOST_CHECK_EQUAL( oss.str(), "22/7" );
}
@@ -966,4 +975,37 @@
#endif
}
+// The bug/patch numbers for the above 3 tests are from our SourceForge repo
+// before we moved to our own SVN & Trac server. At the time this note is
+// written, it seems that SourceForge has reset their tracking numbers at least
+// once, so I don't know how to recover those old tickets. The ticket numbers
+// for the following tests are from our SVN/Trac repo.
+
+//"narrowing conversion error with -std=c++0x in operator< with int_type != int"
+BOOST_AUTO_TEST_CASE( ticket_5855_test )
+{
+ // The internals of operator< currently store a structure of two int_type
+ // (where int_type is the component type of a boost::rational template
+ // class) and two computed types. These computed types, results of
+ // arithmetic operations among int_type values, are either int_type
+ // themselves or a larger type that can implicitly convert to int_type.
+ // Those conversions aren't usually a problem. But when an arithmetic
+ // operation involving two values of a built-in scalar type smaller than int
+ // are involved, the result is an int. But the resulting int-to-shorter
+ // conversion is considered narrowing, resulting in a warning or error on
+ // some compilers. Notably, C++11 compilers are supposed to consider it an
+ // error.
+ //
+ // The solution is to force an explicit conversion, although it's otherwise
+ // not needed. (The compiler can rescind the narrowing warning if the
+ // results of the larger type still fit in the smaller one, and that proof
+ // can be generated at constexpr time.)
+ typedef short shorter_than_int_type;
+ typedef boost::rational<shorter_than_int_type> rational_type;
+
+ bool const dummy = rational_type() < rational_type();
+
+ BOOST_REQUIRE( !dummy );
+}
+
BOOST_AUTO_TEST_SUITE_END()
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk