From ea45295200abb6b9b498e97fbef37567315dddbe Mon Sep 17 00:00:00 2001 From: Ed Catmur Date: Tue, 18 Jan 2022 14:02:11 +0000 Subject: [PATCH] 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