
Paul A Bristow ha escrito:
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Joaquín Mª López Muñoz Sent: 08 October 2007 18:37 To: boost@lists.boost.org Subject: [boost] [lexical_cast][STLport 4.5.3][trunk] static assertion failed in boost/detail/lcast_precision.hpp
Compiling the following snippet in MSVC++ 6.5 + STLport 4.5.3 with the trunk
#include <boost/lexical_cast.hpp>
int main() { return 0; }
results in
...\boost\detail\lcast_precision.hpp(79) : error C2027: use of undefined type 'STATIC_ASSERTION_FAILURE<0>' ...\boost\detail\lcast_precision.hpp(89) : see reference to class template instantiation 'boost::detail::lcast_precision<T>' being compiled
[...]
I can't see an obvious cause (presume it works OK on other platforms), so I can only suggest breaking this down into separate assertions to see which one is causing the trouble, and perhaps getting the values of std::limits<T>::digits and boost::is_abstract<T>.
It seems that the suitable precision (decimal digits to use to get the full accuracy for type T) can't be calculated.
It would also be useful to see what T is? Is this some funny type for which std::numeric_limits isn't properly specialised?
OK, I think I've got it: MSVC++ 6.5 behaves funny with static constants inside templates, as it does not see their correct value during template parsing. For instance, the following: #include <boost/config.hpp> #include <boost/static_assert.hpp> template<typename T> struct foo { BOOST_STATIC_CONSTANT(int,x=2); BOOST_STATIC_ASSERT(x==2); }; int main() { return 0; } fails at the static assertion line (x is seen as 1, btw). After instantiation, however, the static constant holds the correct value, this phenomenon only happens at the parsing stage. So, this is the problem with boost/detail/lcast_precision.hpp in MSVC++ 6.5 + STLport 4.5.3; when using the native Dinkumware stdlib the static assertions pass by pure chance, as they are affected by the same compiler bug. The attached diff simply omits the offending assertions for MSVC++ 6.0/7.0. Is it OK to commit? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Index: lcast_precision.hpp =================================================================== --- lcast_precision.hpp (revision 39833) +++ lcast_precision.hpp (working copy) @@ -68,19 +68,23 @@ BOOST_STATIC_CONSTANT(unsigned int, precision_dec = limits::digits10 + 1U); +#if !defined(BOOST_MSVC)||!(BOOST_MSVC<1310) BOOST_STATIC_ASSERT(!is_specialized_dec || precision_dec <= streamsize_max + 0UL ); +#endif BOOST_STATIC_CONSTANT(unsigned long, precision_bin = 2UL + limits::digits * 30103UL / 100000UL ); +#if !defined(BOOST_MSVC)||!(BOOST_MSVC<1310) BOOST_STATIC_ASSERT(!is_specialized_bin || limits::digits + 0UL < ULONG_MAX / 30103UL && precision_bin > limits::digits10 + 0UL && precision_bin <= streamsize_max + 0UL ); +#endif BOOST_STATIC_CONSTANT(std::streamsize, value = is_specialized_bin ? precision_bin