From ea45295200abb6b9b498e97fbef37567315dddbe Mon Sep 17 00:00:00 2001 From: Ed Catmur Date: Tue, 18 Jan 2022 14:02:11 +0000 Subject: [PATCH 1/2] Check that lazy_ostream argument is printable The operator() is not instantiated till later, which makes it difficult to locate an erroneous usage of <<. Place a static_assert in the ctor (copied from print_helper.hpp) to check at construction time, which will point back to the << site. --- include/boost/test/utils/lazy_ostream.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/boost/test/utils/lazy_ostream.hpp b/include/boost/test/utils/lazy_ostream.hpp index 2d1edbed8e..7d62fd46b1 100644 --- a/include/boost/test/utils/lazy_ostream.hpp +++ b/include/boost/test/utils/lazy_ostream.hpp @@ -15,6 +15,10 @@ #include #include +// Boost +#include +#include + // STL #include @@ -75,6 +79,8 @@ class lazy_ostream_impl : public lazy_ostream { , m_prev( prev ) , m_value( value ) { + BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift::value), + "Type has to implement operator<< to be printable"); } std::ostream& operator()( std::ostream& ostr ) const BOOST_OVERRIDE From d3a47fe0b1e3812289a1bc92a0f09f128b44e1f3 Mon Sep 17 00:00:00 2001 From: Raffi Enficiaud Date: Mon, 7 Mar 2022 21:19:05 +0100 Subject: [PATCH 2/2] Change log --- doc/closing_chapters/change_log.qbk | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/closing_chapters/change_log.qbk b/doc/closing_chapters/change_log.qbk index 90c4fc4d30..64eeb2c0de 100644 --- a/doc/closing_chapters/change_log.qbk +++ b/doc/closing_chapters/change_log.qbk @@ -43,6 +43,7 @@ Boost.Test releases: # [pull_request 275] Replace anonymous `enum` arity with `static constexpr` # [pull_request 278] Use `boost_test_print_type` customization point in `lazy_ostream` # [pull_request 281] Export `execution_aborted` exception to allow catching it from outside the DLL +# [pull_request 323] Check that `lazy_ostream` argument is printable [#ref_CHANGE_LOG_3_14][h4 Boost.Test v3.14 / boost 1.74]