From 38aa3705d036c8841b6790dfe60ece4310efaf6f Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Fri, 27 Apr 2018 12:37:00 +0900 Subject: [PATCH] Added test for unused_type --- test/Jamfile | 1 + test/support/unused.cpp | 95 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/support/unused.cpp diff --git a/test/Jamfile b/test/Jamfile index a61239d0..3a358045 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -266,6 +266,7 @@ project [ compile support/and.cpp : [ requires cxx11_variadic_templates ] ] [ compile support/tag_of.cpp ] + [ compile support/unused.cpp ] # [ compile-fail xxx.cpp ] diff --git a/test/support/unused.cpp b/test/support/unused.cpp new file mode 100644 index 00000000..28d2ffda --- /dev/null +++ b/test/support/unused.cpp @@ -0,0 +1,95 @@ +/*============================================================================= + Copyright (c) 2018 Kohei Takahashi + + 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) +==============================================================================*/ + +#include +#include +#include +#include +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +#include +#endif + +struct T { }; + +void unused_construction() +{ + boost::fusion::unused_type dephault; + + boost::fusion::unused_type BOOST_ATTRIBUTE_UNUSED parenthesis(); +#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX + boost::fusion::unused_type BOOST_ATTRIBUTE_UNUSED brace{}; + boost::fusion::unused_type BOOST_ATTRIBUTE_UNUSED list_copy = {}; +#endif + + boost::fusion::unused_type copy_copy BOOST_ATTRIBUTE_UNUSED = dephault; + boost::fusion::unused_type copy_direct BOOST_ATTRIBUTE_UNUSED (dephault); +#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX + boost::fusion::unused_type copy_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {dephault}; + boost::fusion::unused_type copy_direct_brace BOOST_ATTRIBUTE_UNUSED {dephault}; +#endif + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + boost::fusion::unused_type move_copy BOOST_ATTRIBUTE_UNUSED = std::move(dephault); + boost::fusion::unused_type move_direct BOOST_ATTRIBUTE_UNUSED (std::move(dephault)); +#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX + boost::fusion::unused_type move_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {std::move(dephault)}; + boost::fusion::unused_type move_direct_brace BOOST_ATTRIBUTE_UNUSED {std::move(dephault)}; +#endif +#endif + + + T value; + + boost::fusion::unused_type T_copy_copy BOOST_ATTRIBUTE_UNUSED = value; + boost::fusion::unused_type T_copy_direct BOOST_ATTRIBUTE_UNUSED (value); +#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX + boost::fusion::unused_type T_copy_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {value}; + boost::fusion::unused_type T_copy_direct_brace BOOST_ATTRIBUTE_UNUSED {value}; +#endif + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + boost::fusion::unused_type T_move_copy BOOST_ATTRIBUTE_UNUSED = std::move(value); + boost::fusion::unused_type T_move_direct BOOST_ATTRIBUTE_UNUSED (std::move(value)); +#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX + boost::fusion::unused_type T_move_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {std::move(value)}; + boost::fusion::unused_type T_move_direct_brace BOOST_ATTRIBUTE_UNUSED {std::move(value)}; +#endif +#endif +} + +void unused_assignment() +{ + boost::fusion::unused_type val1, val2; + + val1 = val2; +#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX + val1 = {}; +#endif +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + val1 = std::move(val2); +#endif + + + T value; + + val1 = value; +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + val1 = std::move(value); +#endif +} + +boost::type_traits::yes_type test_unused(boost::fusion::detail::unused_only const&); +boost::type_traits::no_type test_unused(...); + +void only_unused() +{ + BOOST_STATIC_ASSERT((sizeof(test_unused(boost::fusion::unused)) == sizeof(boost::type_traits::yes_type))); + BOOST_STATIC_ASSERT((sizeof(test_unused(0)) == sizeof(boost::type_traits::no_type))); + + boost::fusion::unused_type my_unused; + BOOST_STATIC_ASSERT((sizeof(test_unused(my_unused)) == sizeof(boost::type_traits::yes_type))); +}