From 3bf66ca256eb5259f6ab35303d775f27508b1f42 Mon Sep 17 00:00:00 2001 From: onqtam Date: Tue, 28 Mar 2017 18:09:00 +0300 Subject: using a static assert instead of deleting/hiding the forbidden overload for rvalues - relates #23 relates #48 --- doctest/doctest.h | 11 ++++------- doctest/parts/doctest_fwd.h | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) (limited to 'doctest') diff --git a/doctest/doctest.h b/doctest/doctest.h index d4bfd84..968251c 100644 --- a/doctest/doctest.h +++ b/doctest/doctest.h @@ -1415,14 +1415,11 @@ namespace detail } #ifdef DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#ifdef DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS template - ContextBuilder& operator<<(const T&&) = delete; -#else // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS - private: - template - ContextBuilder& operator<<(const T&&); -#endif // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS + ContextBuilder& operator<<(const T&&) { + DOCTEST_STATIC_ASSERT(deferred_false::value, Cannot_pass_temporaries_or_rvalues_to_the_streaming_operator_because_it_caches_pointers_to_the_passed_objects_for_lazy_evaluation); + return *this; + } #endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES }; diff --git a/doctest/parts/doctest_fwd.h b/doctest/parts/doctest_fwd.h index 7b99156..7081705 100644 --- a/doctest/parts/doctest_fwd.h +++ b/doctest/parts/doctest_fwd.h @@ -1412,14 +1412,11 @@ namespace detail } #ifdef DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#ifdef DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS template - ContextBuilder& operator<<(const T&&) = delete; -#else // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS - private: - template - ContextBuilder& operator<<(const T&&); -#endif // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS + ContextBuilder& operator<<(const T&&) { + DOCTEST_STATIC_ASSERT(deferred_false::value, Cannot_pass_temporaries_or_rvalues_to_the_streaming_operator_because_it_caches_pointers_to_the_passed_objects_for_lazy_evaluation); + return *this; + } #endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES }; -- cgit v1.2.3