[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Fwd: How did this unit test fail?
From: |
Greg Chicares |
Subject: |
Re: [lmi] Fwd: How did this unit test fail? |
Date: |
Tue, 27 Mar 2018 18:43:43 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 2018-03-27 11:50, Vadim Zeitlin wrote:
[...]
> In the meanwhile, one workaround I may report is that removing the use of
> "constexpr" from bourn_cast.hpp definitely avoids the problem. Considering
> that this is required for building with clang anyhow because it (correctly,
> AFAICS) disallows the use of non-constexpr lmi::TypeInfo and
> std::ostringstream classes in a constexpr function, perhaps we should do
> this just to make sure to avoid the problem?
Excellent: std::ostringstream has no constexpr ctor; nasal demons follow.
As currently written, 'constexpr' is wrong in floating-to-integral function:
template<typename To, typename From>
constexpr inline To bourn_cast(From from, std::true_type, std::false_type)
...std::ostringstream...
and therefore it's wrong on the general version that calls that function:
template<typename To, typename From>
constexpr inline To bourn_cast(From from)
so we can either...
- remove constexpr rather globally from bourn_cast(), which really, really
wants to be constexpr; or
- remove diagnostic code that has never been found useful in practice.
Could you please test the Visigothic proof of concept that I hacked out
below? It works perfectly here, both of these ways:
/opt/lmi/src/lmi[0]$make $coefficiency unit_tests
unit_test_targets=bourn_cast_test.exe 2>&1 |less -S
/opt/lmi/src/lmi[0]$make $coefficiency unit_tests
unit_test_targets=bourn_cast_test.exe build_type=safestdlib 2>&1 |less -S
and if all your compilers like it, I'll lay my axe aside and rework it
carefully for committal.
---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
diff --git a/bourn_cast.hpp b/bourn_cast.hpp
index 50d1714a..728a0c05 100644
--- a/bourn_cast.hpp
+++ b/bourn_cast.hpp
@@ -185,6 +185,9 @@ constexpr inline To bourn_cast(From from, std::true_type,
std::false_type)
To const r = static_cast<To>(from);
if(r != from)
{
+#if 1
+ throw std::runtime_error("Cast would not preserve value.");
+#else // 0
lmi::TypeInfo from_type(typeid(From));
lmi::TypeInfo to_type(typeid(To ));
std::ostringstream oss;
@@ -195,6 +198,7 @@ constexpr inline To bourn_cast(From from, std::true_type,
std::false_type)
<< " would not preserve value."
;
throw std::runtime_error(oss.str());
+#endif // 0
}
return r;
}
diff --git a/bourn_cast_test.cpp b/bourn_cast_test.cpp
index 96687e61..ed360bbb 100644
--- a/bourn_cast_test.cpp
+++ b/bourn_cast_test.cpp
@@ -653,7 +653,7 @@ void mete_static()
{
z = static_cast<To>(j);
}
- (void)&z;
+ stifle_warning_for_unused_variable(z);
}
/// Speed test: convert one million times, using bourn_cast.
@@ -670,7 +670,7 @@ void mete_bourn()
{
z = bourn_cast<To>(j);
}
- (void)&z;
+ stifle_warning_for_unused_variable(z);
}
void assay_speed()
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------
- [lmi] How did this unit test fail?, Greg Chicares, 2018/03/19
- Re: [lmi] How did this unit test fail?, Vadim Zeitlin, 2018/03/19
- Message not available
- Re: [lmi] Fwd: How did this unit test fail?, Vadim Zeitlin, 2018/03/22
- Re: [lmi] Fwd: How did this unit test fail?, Greg Chicares, 2018/03/22
- Re: [lmi] Fwd: How did this unit test fail?, Vadim Zeitlin, 2018/03/22
- Re: [lmi] Fwd: How did this unit test fail?, Vadim Zeitlin, 2018/03/27
- Re: [lmi] Fwd: How did this unit test fail?,
Greg Chicares <=
- Re: [lmi] Fwd: How did this unit test fail?, Vadim Zeitlin, 2018/03/27
- Re: [lmi] Fwd: How did this unit test fail?, Greg Chicares, 2018/03/28
- Re: [lmi] Fwd: How did this unit test fail?, Vadim Zeitlin, 2018/03/28