[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 58347e4 3/4: Fix defect introduced 20050203T1
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 58347e4 3/4: Fix defect introduced 20050203T1603Z: bogus exception |
Date: |
Wed, 29 Jan 2020 08:00:57 -0500 (EST) |
branch: master
commit 58347e43cbe3b23faf3da07798fd624623baf5b3
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Fix defect introduced 20050203T1603Z: bogus exception
See:
https://lists.nongnu.org/archive/html/lmi/2018-11/msg00034.html
https://lists.nongnu.org/archive/html/lmi/2020-01/msg00000.html
et seqq.
---
stream_cast.hpp | 6 +-----
stream_cast_test.cpp | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/stream_cast.hpp b/stream_cast.hpp
index 3e74f8e..49b06fd 100644
--- a/stream_cast.hpp
+++ b/stream_cast.hpp
@@ -122,11 +122,7 @@ To stream_cast(From from, To = To())
{
err << "Output failed ";
}
- else if(!(interpreter >> std::ws))
- {
- err << "Trailing whitespace remains ";
- }
- else if(!interpreter.eof())
+ else if(!(interpreter >> std::ws).eof())
{
err << "Unconverted data remains ";
}
diff --git a/stream_cast_test.cpp b/stream_cast_test.cpp
index e47c61e..08cea91 100644
--- a/stream_cast_test.cpp
+++ b/stream_cast_test.cpp
@@ -70,6 +70,40 @@ int test_main(int, char*[])
{
std::string s;
+ // First, test each exception coded in the primary template.
+
+ BOOST_TEST_THROW
+ (stream_cast<std::string>(static_cast<std::streambuf*>(nullptr))
+ ,std::runtime_error
+ ,lmi_test::what_regex("^Input failed")
+ );
+
+ BOOST_TEST_THROW
+ (stream_cast<double>("INF")
+ ,std::runtime_error
+ ,lmi_test::what_regex("^Output failed")
+ );
+
+ // Throw if any trailing input remains...
+ BOOST_TEST_THROW
+ (stream_cast<double>("3.14 59")
+ ,std::runtime_error
+ ,lmi_test::what_regex("^Unconverted data remains")
+ );
+ BOOST_TEST_THROW
+ (stream_cast<double>("3.14\r59")
+ ,std::runtime_error
+ ,lmi_test::what_regex("^Unconverted data remains")
+ );
+ // ...unless it's all whitespace...
+ BOOST_TEST_EQUAL(2, stream_cast<int>("2\r"));
+ // ...as designated by blank_is_not_whitespace_locale()
+ BOOST_TEST_THROW
+ (stream_cast<double>("3.14 ")
+ ,std::runtime_error
+ ,lmi_test::what_regex("^Unconverted data remains")
+ );
+
// Conversion from an empty std::string to another std::string
// works only because a specialization is used in that case.
// This would fail if the type converted to were of a different