From fc135e0d72610e13c6dac0aa11e09f710526f022 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sun, 9 Sep 2018 15:00:49 -0400 Subject: [PATCH] Avoid inheritance for final types in compressed_pair --- include/boost/detail/compressed_pair.hpp | 25 +++++++---- test/Jamfile.v2 | 1 + test/compressed_pair_final_test.cpp | 55 ++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 test/compressed_pair_final_test.cpp diff --git a/include/boost/detail/compressed_pair.hpp b/include/boost/detail/compressed_pair.hpp index 5dc21e2..b090a72 100644 --- a/include/boost/detail/compressed_pair.hpp +++ b/include/boost/detail/compressed_pair.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -42,6 +43,14 @@ class compressed_pair; namespace details { + template::value> + struct compressed_pair_empty + : ::boost::false_type { }; + + template + struct compressed_pair_empty + : ::boost::is_empty { }; + // JM altered 26 Jan 2000: template struct compressed_pair_switch; @@ -343,8 +352,8 @@ class compressed_pair T1, T2, ::boost::is_same::type, typename remove_cv::type>::value, - ::boost::is_empty::value, - ::boost::is_empty::value>::value> + ::boost::details::compressed_pair_empty::value, + ::boost::details::compressed_pair_empty::value>::value> { private: typedef details::compressed_pair_imp::type, typename remove_cv::type>::value, - ::boost::is_empty::value, - ::boost::is_empty::value>::value> base; + ::boost::details::compressed_pair_empty::value, + ::boost::details::compressed_pair_empty::value>::value> base; public: typedef T1 first_type; typedef T2 second_type; @@ -388,8 +397,8 @@ class compressed_pair T, T, ::boost::is_same::type, typename remove_cv::type>::value, - ::boost::is_empty::value, - ::boost::is_empty::value>::value> + ::boost::details::compressed_pair_empty::value, + ::boost::details::compressed_pair_empty::value>::value> { private: typedef details::compressed_pair_imp::type, typename remove_cv::type>::value, - ::boost::is_empty::value, - ::boost::is_empty::value>::value> base; + ::boost::details::compressed_pair_empty::value, + ::boost::details::compressed_pair_empty::value>::value> base; public: typedef T first_type; typedef T second_type; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7fd5b2f..739edc0 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -16,6 +16,7 @@ run binary_test.cpp ; run call_traits_test.cpp : -u ; run compressed_pair_test.cpp ; +run compressed_pair_final_test.cpp ; run iterators_test.cpp ; diff --git a/test/compressed_pair_final_test.cpp b/test/compressed_pair_final_test.cpp new file mode 100644 index 0000000..247f3fc --- /dev/null +++ b/test/compressed_pair_final_test.cpp @@ -0,0 +1,55 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include +#if !defined(BOOST_NO_CXX11_FINAL) +#include +#include + +struct type1 { + operator bool() const { + return false; + } +}; + +struct type2 final { + operator bool() const { + return false; + } +}; + +#if !defined(BOOST_IS_FINAL) +namespace boost { + +template<> +struct is_final + : true_type { }; + +} /* boost*/ +#endif + +template +void test() +{ + boost::compressed_pair p; + BOOST_TEST(!p.first()); + BOOST_TEST(!p.second()); +} + +int main() +{ + test(); + test(); + test(); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif