Skip to content

Commit

Permalink
Check that lazy_ostream argument is printable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ecatmur authored and raffienficiaud committed Mar 2, 2023
1 parent 1074032 commit ea45295
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/boost/test/utils/lazy_ostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <boost/test/detail/config.hpp>
#include <boost/test/tools/detail/print_helper.hpp>

// Boost
#include <boost/static_assert.hpp>
#include <boost/type_traits/has_left_shift.hpp>

// STL
#include <iosfwd>

Expand Down Expand Up @@ -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<std::ostream,T>::value),
"Type has to implement operator<< to be printable");
}

std::ostream& operator()( std::ostream& ostr ) const BOOST_OVERRIDE
Expand Down

0 comments on commit ea45295

Please sign in to comment.