From a78c25e4ab6681b80403240dda2f6a98d041fb32 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sat, 20 Apr 2019 03:04:06 -0400 Subject: [PATCH] Print type with cvref qualifiers --- include/boost/core/lightweight_test_trait.hpp | 52 ++++++++++++++++++- test/lightweight_test_fail12.cpp | 26 +++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/include/boost/core/lightweight_test_trait.hpp b/include/boost/core/lightweight_test_trait.hpp index 73770f4..26042c6 100644 --- a/include/boost/core/lightweight_test_trait.hpp +++ b/include/boost/core/lightweight_test_trait.hpp @@ -13,6 +13,9 @@ // // Copyright 2014 Peter Dimov // +// Copyright 2019 Glen Joseph Fernandes +// (glenjofe@gmail.com) +// // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt @@ -20,6 +23,7 @@ #include #include #include +#include namespace boost { @@ -27,6 +31,50 @@ namespace boost namespace detail { +template struct test_print { }; + +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << boost::core::demangled_name(BOOST_CORE_TYPEID(T)); +} + +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << test_print(); +} + +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << test_print() << " const"; +} + +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << test_print() << " volatile"; +} + +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << test_print() << " const volatile"; +} + +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << test_print(); +} + +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << test_print() << " &"; +} + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +template inline std::ostream& operator<<(std::ostream& o, test_print) +{ + return o << test_print() << " &&"; +} +#endif + template< class T > inline void test_trait_impl( char const * trait, void (*)( T ), bool expected, char const * file, int line, char const * function ) { @@ -64,8 +112,8 @@ template inline void test_trait_same_impl( char const * type BOOST_LIGHTWEIGHT_TEST_OSTREAM << file << "(" << line << "): test 'is_same<" << types << ">'" << " failed in function '" << function - << "' ('" << boost::core::demangled_name( BOOST_CORE_TYPEID(T1) ) - << "' != '" << boost::core::demangled_name( BOOST_CORE_TYPEID(T2) ) << "')" + << "' ('" << test_print() + << "' != '" << test_print() << "')" << std::endl; ++test_results().errors(); diff --git a/test/lightweight_test_fail12.cpp b/test/lightweight_test_fail12.cpp index 122dced..bf0ce59 100644 --- a/test/lightweight_test_fail12.cpp +++ b/test/lightweight_test_fail12.cpp @@ -9,6 +9,7 @@ // #include +#include struct X { @@ -20,6 +21,21 @@ template struct Y typedef T1 type; }; +typedef int I1; +typedef const int I2; +typedef volatile int I3; +typedef const volatile int I4; +typedef int& I5; +typedef const int& I6; +typedef volatile int& I7; +typedef const volatile int& I8; +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +typedef int&& I9; +typedef const int&& I10; +typedef volatile int&& I11; +typedef const volatile int&& I12; +#endif + int main() { BOOST_TEST_TRAIT_SAME(char[1], char[2]); @@ -32,6 +48,14 @@ int main() BOOST_TEST_TRAIT_SAME(X, Y); BOOST_TEST_TRAIT_SAME(X::type, Y::type); BOOST_TEST_TRAIT_SAME(Y, Y); + BOOST_TEST_TRAIT_SAME(I1, I2); + BOOST_TEST_TRAIT_SAME(I3, I4); + BOOST_TEST_TRAIT_SAME(I5, I6); + BOOST_TEST_TRAIT_SAME(I7, I8); +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + BOOST_TEST_TRAIT_SAME(I9, I10); + BOOST_TEST_TRAIT_SAME(I11, I12); +#endif - return boost::report_errors() == 10; + return boost::report_errors() == 16; }