[type_traits] is_base_of<> GCC error for v1.42.0

Hello all, The following code gives the GCC compiler error below for Boost 1.42.0 while it compiles just fine for Boost 1.34.1. Is this a bug in Boost.TypeTraits for 1.42.0? // File: b00.cpp #include <boost/type_traits.hpp> #include <iostream> struct y {}; struct x: y { static const bool v = boost::is_base_of<y, x>::value; }; int main() { std::cout << x::v << std::endl; return 0; } $ g++ -Wall -Werror b00.cpp /usr/include/boost/type_traits/is_base_and_derived.hpp: In instantiation of ‘boost::detail::is_base_and_derived_impl2<y, x>’: /usr/include/boost/type_traits/is_base_and_derived.hpp:219: instantiated from ‘const bool boost::detail::is_base_and_derived_impl<y, x>::value’ /usr/include/boost/type_traits/is_base_of.hpp:29: instantiated from ‘const bool boost::detail::is_base_of_imp<y, x>::value’ /usr/include/boost/type_traits/is_base_of.hpp:35: instantiated from ‘boost::is_base_of<y, x>’ b00.cpp:8: instantiated from here /usr/include/boost/type_traits/is_base_and_derived.hpp:145: error: invalid application of ‘sizeof’ to incomplete type ‘x’ /usr/include/boost/type_traits/is_base_and_derived.hpp:145: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’ $ g++ --version g++ (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thank you. -- Lorenzo

The following code gives the GCC compiler error below for Boost 1.42.0 while it compiles just fine for Boost 1.34.1.
Is this a bug in Boost.TypeTraits for 1.42.0?
No it's a feature... sort of. Part of the requirements on the template parameters for is_base_of are that they are complete types, if they're not complete types then our implementation can silently do the wrong thing, so we assert that they are complete inside the implementation. The change was introduced as a bug fix to another issue, and simply asserts what we have always documented, so I'm afraid you're out of luck in that particular use case :-( The same applies to std::is_base_of I believe as well. The only workaround I can think of would be to forward declare the two classes and then specialize is_base_of for that use case. HTH, John.

On Sun, May 9, 2010 at 5:04 AM, John Maddock <boost.regex@virgin.net> wrote:
The following code gives the GCC compiler error below for Boost 1.42.0 while it compiles just fine for Boost 1.34.1.
Is this a bug in Boost.TypeTraits for 1.42.0?
No it's a feature... sort of.
Part of the requirements on the template parameters for is_base_of are that they are complete types, if they're not complete types then our implementation can silently do the wrong thing, so we assert that they are complete inside the implementation. The change was introduced as a bug fix to another issue, and simply asserts what we have always documented, so I'm afraid you're out of luck in that particular use case :-(
The same applies to std::is_base_of I believe as well.
OK, I see (and now I remember reading about this requirement in the documentation a while back). I was (incorrectly) using this together with MPL_ASSERT just to raise a more descriptive error message. However, this static check is not necessary as my code will eventually fail somehow if `y` is not a base of `x`. Thank you for the clarification. -- Lorenzo

----- Original Message ----- From: "Lorenzo Caminiti" <lorcaminiti@gmail.com> To: <boost@lists.boost.org> Sent: Saturday, May 08, 2010 10:38 PM Subject: [boost] [type_traits] is_base_of<> GCC error for v1.42.0 Hello all, The following code gives the GCC compiler error below for Boost 1.42.0 while it compiles just fine for Boost 1.34.1. Is this a bug in Boost.TypeTraits for 1.42.0? // File: b00.cpp #include <boost/type_traits.hpp> #include <iostream> struct y {}; struct x: y { static const bool v = boost::is_base_of<y, x>::value; }; _______________________________________________ Hi, As John stated this is the expected behavior. If you need it, you can define the constant once the classes are completly declared. struct y {}; struct x: y { static const bool v; }; const bool x::v = boost::is_base_of<y, x>::value; HTH, Vicente
participants (3)
-
John Maddock
-
Lorenzo Caminiti
-
vicente.botet