From 24b7d226d3316d36711c40b7ca854c2b2d4565be Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 16 May 2015 18:39:49 +0100 Subject: [PATCH 1/2] Add fix for false positives in is_virtual_base_of See https://svn.boost.org/trac/boost/ticket/11309 --- include/boost/type_traits/is_virtual_base_of.hpp | 15 +++++++++++++++ test/is_virtual_base_of_test.cpp | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/boost/type_traits/is_virtual_base_of.hpp b/include/boost/type_traits/is_virtual_base_of.hpp index 33db914..3daad1b 100644 --- a/include/boost/type_traits/is_virtual_base_of.hpp +++ b/include/boost/type_traits/is_virtual_base_of.hpp @@ -36,6 +36,17 @@ struct is_virtual_base_of_impl template struct is_virtual_base_of_impl { + union max_align + { + unsigned u; + unsigned long ul; + void* v; + double d; + long double ld; +#ifndef BOOST_NO_LONG_LONG + long long ll; +#endif + }; #ifdef __BORLANDC__ struct boost_type_traits_internal_struct_X : public virtual Derived, public virtual Base { @@ -43,6 +54,7 @@ struct is_virtual_base_of_impl boost_type_traits_internal_struct_X(const boost_type_traits_internal_struct_X&); boost_type_traits_internal_struct_X& operator=(const boost_type_traits_internal_struct_X&); ~boost_type_traits_internal_struct_X()throw(); + max_align data[4]; }; struct boost_type_traits_internal_struct_Y : public virtual Derived { @@ -50,6 +62,7 @@ struct is_virtual_base_of_impl boost_type_traits_internal_struct_Y(const boost_type_traits_internal_struct_Y&); boost_type_traits_internal_struct_Y& operator=(const boost_type_traits_internal_struct_Y&); ~boost_type_traits_internal_struct_Y()throw(); + max_align data[4]; }; #else struct boost_type_traits_internal_struct_X : public Derived, virtual Base @@ -58,6 +71,7 @@ struct is_virtual_base_of_impl boost_type_traits_internal_struct_X(const boost_type_traits_internal_struct_X&); boost_type_traits_internal_struct_X& operator=(const boost_type_traits_internal_struct_X&); ~boost_type_traits_internal_struct_X()throw(); + max_align data[16]; }; struct boost_type_traits_internal_struct_Y : public Derived { @@ -65,6 +79,7 @@ struct is_virtual_base_of_impl boost_type_traits_internal_struct_Y(const boost_type_traits_internal_struct_Y&); boost_type_traits_internal_struct_Y& operator=(const boost_type_traits_internal_struct_Y&); ~boost_type_traits_internal_struct_Y()throw(); + max_align data[16]; }; #endif BOOST_STATIC_CONSTANT(bool, value = (sizeof(boost_type_traits_internal_struct_X)==sizeof(boost_type_traits_internal_struct_Y))); diff --git a/test/is_virtual_base_of_test.cpp b/test/is_virtual_base_of_test.cpp index 2877b4a..256e67c 100644 --- a/test/is_virtual_base_of_test.cpp +++ b/test/is_virtual_base_of_test.cpp @@ -38,6 +38,13 @@ public: virtual int X(); }; +// +// These are from https://svn.boost.org/trac/boost/ticket/11309 +// +struct bug11309_A { int a; }; +struct bug11309_B : public virtual bug11309_A {}; +struct bug11309_C : public bug11309_A { virtual ~bug11309_C() {} }; + TT_TEST_BEGIN(is_virtual_base_of) BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of::value), false); @@ -75,6 +82,12 @@ BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of:: BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of::value), false); BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of::value), false); +// +// Bug cases: +// +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of::value), false); +BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_virtual_base_of::value), true); + TT_TEST_END From 9f489b0d718c3754a1d176ec7e88964320457a1e Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 21 May 2015 18:39:50 +0100 Subject: [PATCH 2/2] Add tests to detect, https://svn.boost.org/trac/boost/ticket/11324. --- test/has_nothrow_constr_test.cpp | 16 ++++++++++++++++ test/has_trivial_constr_test.cpp | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/test/has_nothrow_constr_test.cpp b/test/has_nothrow_constr_test.cpp index 4ac8032..fe365ab 100644 --- a/test/has_nothrow_constr_test.cpp +++ b/test/has_nothrow_constr_test.cpp @@ -12,6 +12,21 @@ # include #endif +class bug11324_base +{ +public: + bug11324_base & operator=(const bug11324_base&){ throw int(); } + virtual ~bug11324_base() {} +}; + +class bug11324_derived : public bug11324_base +{ +public: + char data; + explicit bug11324_derived(char arg) : data(arg) {} +}; + + TT_TEST_BEGIN(has_nothrow_constructor) BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor::value, true); @@ -162,6 +177,7 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor: BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_constructor::value, false); TT_TEST_END diff --git a/test/has_trivial_constr_test.cpp b/test/has_trivial_constr_test.cpp index e163a6b..8db4ede 100644 --- a/test/has_trivial_constr_test.cpp +++ b/test/has_trivial_constr_test.cpp @@ -12,6 +12,22 @@ # include #endif + +class bug11324_base +{ +public: + bug11324_base & operator=(const bug11324_base&){ throw int(); } + virtual ~bug11324_base() {} +}; + +class bug11324_derived : public bug11324_base +{ +public: + char data; + explicit bug11324_derived(char arg) : data(arg) {} +}; + + TT_TEST_BEGIN(has_trivial_constructor) BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor::value, true); @@ -169,6 +185,7 @@ BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_trivial_constructor::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_constructor::value, false); TT_TEST_END