Boost logo

Boost :

Subject: Re: [boost] [chrono] New Features + Bug fixes + Updateddocumentation
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2009-12-12 08:40:27


On Dec 12, 2009, at 5:22 AM, vicente.botet wrote:

> I have also installed MSVC and I have an issue with the ratio_fail_test1.cpp test. MSVC report a warning instead of an error.
>
> compile-c-c++ ..\..\..\bin.v2\libs\chrono\test\ratio_fail_test1.test\msvc-9.0express\debug\asynch-exceptions-on\ratio_fail_test1.obj
> ratio_fail_test1.cpp
> C:\cygwin\boost_1_41_0\boost/ratio.hpp(217) : warning C4307: '*' : integral constant overflow
> C:\cygwin\boost_1_41_0\boost/ratio.hpp(394) : see reference to class template instantiation 'boost::detail::ll_mul<X,Y>' being compiled
> with
> [
> X=0x7fffffffffffffff,
> Y=0x3fffffffffffffff
> ]
> ratio_fail_test1.cpp(12) : see reference to class template instantiation 'boost::ratio_multiply<R1,R2>' being compiled
> with
> [
> R1=R1,
> R2=R2
> ]
> C:\cygwin\boost_1_41_0\boost/ratio.hpp(217) : warning C4307: '*' : integral constant overflow
> C:\cygwin\boost_1_41_0\boost/ratio.hpp(395) : see reference to class template instantiation 'boost::detail::ll_mul<X,Y>' being compiled
> with
> [
> X=0x3ffffffffffffff8,
> Y=0x7ffffffffffffff0
> ]
>
> call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 >nul
> cl /Zm800 -nologo @"..\..\..\bin.v2\libs\chrono\test\ratio_fail_test1.test\msvc-9.0express\debug\asynch-exceptions-on\ratio_fail_test1.obj.rsp"
>
> ...failed compile-c-c++ ..\..\..\bin.v2\libs\chrono\test\ratio_fail_test1.test\msvc-9.0express\debug\asynch-exceptions-on\ratio_fail_test1.obj...
> ...removing ..\..\..\bin.v2\libs\chrono\test\ratio_fail_test1.test\msvc-9.0express\debug\asynch-exceptions-on\ratio_fail_test1.obj
> ...removing outdated ..\..\..\bin.v2\libs\chrono\test\ratio_fail_test1.test\msvc-9.0express\debug\asynch-exceptions-on\ratio_fail_test1.test
>
> I have added
>
> [ compile-fail ratio_fail_test1.cpp : <warnings-as-errors>on ]
>
> and all is right.
>
> Is there another way to make MSVC report an error when there is an integral constant overflow?

The intent is to have ll_mul cause an error with the C++0x feature "static_assert" instead of relying on the compiler to do it. This line:

   static char test[a_x <= max / a_y];

is meant to fail at compile time if there is an overflow during multiplication. I suggest you insert the boost macro version of static_assert (I'm not sure what the syntax is). It has probably already been tuned to work well on MSVC. If you do this throughout, everywhere I've got a commented out static_assert, and arrays of char, I think you'll get what you're looking for. Sorry, I should've done this in the first place.

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk