lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Stream cast problems with trailing spaces and more


From: Greg Chicares
Subject: Re: [lmi] Stream cast problems with trailing spaces and more
Date: Wed, 29 Jan 2020 23:02:34 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0

On 2020-01-29 16:45, Greg Chicares wrote:
[...]
> something in the Standard that led me to believe that an infinity would
> induce "Output failed" here:
> 
>     else if(!(interpreter >> result))
>         {
>         err << "Output failed ";
>         }
> 
> because...well, I can't find the reason now, upon rereading the Standard.
[...]
> If you see better ways to induce these specific failures, please let me
> know.
In "INF", the characters 'I' and 'N'...

  https://cplusplus.github.io/LWG/lwg-active.html#2381
| are correctly parsed by std::strtod, but not by the stream extraction 
operators

...which could explain the outcome you report with clang and msvc, if they
haven't implemented the "proposed resolution".

Instead of casting "INF" to double, how about casting "3" to bool?
This amended test throws the expected exception with gcc-8.3:

diff --git a/stream_cast_test.cpp b/stream_cast_test.cpp
index 08cea91c..cb03adc4 100644
--- a/stream_cast_test.cpp
+++ b/stream_cast_test.cpp
@@ -79,7 +79,7 @@ int test_main(int, char*[])
         );
 
     BOOST_TEST_THROW
-        (stream_cast<double>("INF")
+        (stream_cast<bool>("3")
         ,std::runtime_error
         ,lmi_test::what_regex("^Output failed")
         );

So does this alternative:

diff --git a/stream_cast_test.cpp b/stream_cast_test.cpp
index 08cea91c..c5bf5e18 100644
--- a/stream_cast_test.cpp
+++ b/stream_cast_test.cpp
@@ -79,7 +79,7 @@ int test_main(int, char*[])
         );
 
     BOOST_TEST_THROW
-        (stream_cast<double>("INF")
+        (stream_cast<double>("1.e+099999999")
         ,std::runtime_error
         ,lmi_test::what_regex("^Output failed")
         );

I also tried "100,00.0" and "0x1a.bp+07", but those didn't cause gcc-8.3
to throw the desired exception.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]