From 64a8b36b23183fb19c05c4c99b38eb2cc5de500c Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sat, 4 Sep 2004 10:34:49 +0000 Subject: [PATCH] Added new types boost::long_long_type and boost::ulong_long_type in boost/config.hpp and applied these types in place of "long long" throughout. As a result, almost all of boost now compiles cleanly with -ansi -pedantic with gcc. Changes tested with gcc 3.3, 2.95, VC7.1 and Intel 8. [SVN r24899] --- include/boost/config/suffix.hpp | 15 +++++++++++++ include/boost/limits.hpp | 34 ++++++++++++++++-------------- test/boost_has_long_long.ipp | 5 +++++ test/boost_no_integral_int64_t.ipp | 9 ++++++++ test/boost_no_ll_limits.ipp | 12 +++++++++-- test/limits_test.cpp | 6 ++---- 6 files changed, 59 insertions(+), 22 deletions(-) diff --git a/include/boost/config/suffix.hpp b/include/boost/config/suffix.hpp index 12eca208..563d1a99 100644 --- a/include/boost/config/suffix.hpp +++ b/include/boost/config/suffix.hpp @@ -399,6 +399,21 @@ namespace std { # define BOOST_DEDUCED_TYPENAME #endif +// long long workaround ------------------------------------------// +// On gcc (and maybe other compilers?) long long is alway supported +// but it's use may generate either warnings (with -ansi), or errors +// (with -pedantic -ansi) unless it's use is prefixed by __extension__ +// +namespace boost{ +#ifdef __GNUC__ + __extension__ typedef long long long_long_type; + __extension__ typedef unsigned long long ulong_long_type; +#else + typedef long long long_long_type; + typedef unsigned long long ulong_long_type; +#endif +} + // BOOST_[APPEND_]EXPLICIT_TEMPLATE_[NON_]TYPE macros --------------------------// // // Some compilers have problems with function templates whose diff --git a/include/boost/limits.hpp b/include/boost/limits.hpp index 87982e54..f468dbce 100644 --- a/include/boost/limits.hpp +++ b/include/boost/limits.hpp @@ -24,8 +24,10 @@ // Add missing specializations for numeric_limits: #ifdef BOOST_HAS_MS_INT64 # define BOOST_LLT __int64 +# define BOOST_ULLT unsigned __int64 #else -# define BOOST_LLT long long +# define BOOST_LLT ::boost::long_long_type +# define BOOST_ULLT ::boost::ulong_long_type #endif namespace std @@ -84,23 +86,23 @@ namespace std }; template<> - class numeric_limits + class numeric_limits { public: BOOST_STATIC_CONSTANT(bool, is_specialized = true); #ifdef BOOST_HAS_MS_INT64 - static unsigned BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0ui64; } - static unsigned BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0xFFFFFFFFFFFFFFFFui64; } + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0ui64; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0xFFFFFFFFFFFFFFFFui64; } #elif defined(ULLONG_MAX) && defined(ULLONG_MIN) - static unsigned BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MIN; } - static unsigned BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MAX; } + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MIN; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MAX; } #elif defined(ULONGLONG_MAX) && defined(ULONGLONG_MIN) - static unsigned BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MIN; } - static unsigned BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MAX; } + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MIN; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MAX; } #else - static unsigned BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0uLL; } - static unsigned BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ~0uLL; } + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0uLL; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ~0uLL; } #endif BOOST_STATIC_CONSTANT(int, digits = sizeof(BOOST_LLT) * CHAR_BIT); BOOST_STATIC_CONSTANT(int, digits10 = (CHAR_BIT * sizeof (BOOST_LLT)) * 301L / 1000); @@ -108,8 +110,8 @@ namespace std BOOST_STATIC_CONSTANT(bool, is_integer = true); BOOST_STATIC_CONSTANT(bool, is_exact = true); BOOST_STATIC_CONSTANT(int, radix = 2); - static unsigned BOOST_LLT epsilon() throw() { return 0; }; - static unsigned BOOST_LLT round_error() throw() { return 0; }; + static BOOST_ULLT epsilon() throw() { return 0; }; + static BOOST_ULLT round_error() throw() { return 0; }; BOOST_STATIC_CONSTANT(int, min_exponent = 0); BOOST_STATIC_CONSTANT(int, min_exponent10 = 0); @@ -121,10 +123,10 @@ namespace std BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = false); BOOST_STATIC_CONSTANT(bool, has_denorm = false); BOOST_STATIC_CONSTANT(bool, has_denorm_loss = false); - static unsigned BOOST_LLT infinity() throw() { return 0; }; - static unsigned BOOST_LLT quiet_NaN() throw() { return 0; }; - static unsigned BOOST_LLT signaling_NaN() throw() { return 0; }; - static unsigned BOOST_LLT denorm_min() throw() { return 0; }; + static BOOST_ULLT infinity() throw() { return 0; }; + static BOOST_ULLT quiet_NaN() throw() { return 0; }; + static BOOST_ULLT signaling_NaN() throw() { return 0; }; + static BOOST_ULLT denorm_min() throw() { return 0; }; BOOST_STATIC_CONSTANT(bool, is_iec559 = false); BOOST_STATIC_CONSTANT(bool, is_bounded = false); diff --git a/test/boost_has_long_long.ipp b/test/boost_has_long_long.ipp index b4be93ad..651021b4 100644 --- a/test/boost_has_long_long.ipp +++ b/test/boost_has_long_long.ipp @@ -16,8 +16,13 @@ namespace boost_has_long_long{ int test() { +#ifdef __GNUC__ + __extension__ long long lli = 0LL; + __extension__ unsigned long long ulli = 0uLL; +#else long long lli = 0LL; unsigned long long ulli = 0uLL; +#endif (void)&lli; (void)&ulli; return 0; diff --git a/test/boost_no_integral_int64_t.ipp b/test/boost_no_integral_int64_t.ipp index 9cb970b0..3984808d 100644 --- a/test/boost_no_integral_int64_t.ipp +++ b/test/boost_no_integral_int64_t.ipp @@ -23,11 +23,20 @@ struct llt enum{ value = m }; }; #else +#ifdef __GNUC__ +__extension__ +#endif static const unsigned long long mask = 1uLL << 50; +#ifdef __GNUC__ +__extension__ +#endif template struct llt { +#ifdef __GNUC__ +__extension__ +#endif static const unsigned long long value = m; }; #endif diff --git a/test/boost_no_ll_limits.ipp b/test/boost_no_ll_limits.ipp index 039d16fd..8f7db7dc 100644 --- a/test/boost_no_ll_limits.ipp +++ b/test/boost_no_ll_limits.ipp @@ -16,8 +16,16 @@ namespace boost_no_long_long_numeric_limits{ int test() { - if(0 == std::numeric_limits::is_specialized) return -1; - if(0 == std::numeric_limits::is_specialized) return -1; +#ifdef __GNUC__ +__extension__ +#endif + typedef long long llt; +#ifdef __GNUC__ +__extension__ +#endif + typedef unsigned long long ullt; + if(0 == std::numeric_limits::is_specialized) return -1; + if(0 == std::numeric_limits::is_specialized) return -1; return 0; } diff --git a/test/limits_test.cpp b/test/limits_test.cpp index aac6de25..7ae632d3 100644 --- a/test/limits_test.cpp +++ b/test/limits_test.cpp @@ -170,10 +170,8 @@ int test_main(int, char*[]) typedef unsigned long unsigned_long; test_integral_limits(unsigned_long(), "unsigned long"); #if defined(BOOST_HAS_LONG_LONG) - typedef long long long_long; - test_integral_limits(long_long(), "long long"); - typedef unsigned long long unsigned_long_long; - test_integral_limits(unsigned_long_long(), "unsigned long long"); + test_integral_limits(::boost::long_long_type(), "long long"); + test_integral_limits(::boost::ulong_long_type(), "unsigned long long"); #endif #ifdef BOOST_HAS_MS_INT64 typedef __int64 long_long2;