|
Boost : |
Subject: Re: [boost] bug in type_traits/is_virtual_base_of ??
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2010-02-11 13:36:35
I included the compiler version in the first post, but here it is again. I have expanded upon the bug and provided the actual output of the code. Looking at the implementation of is_virtual_base_of<>, it appears that it makes some assumptions regarding the sizeof() a class with and without virtual inheritance that are perhaps invalid?
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
#include <stdio.h>
#include <boost/type_traits/is_virtual_base_of.hpp>
struct A
{
int x;
};
struct B
{
int y;
};
struct C : public A, public B
{
int z;
};
struct D : public A, virtual public B
{
int z;
};
struct E : public A, public B
{
virtual void test(){};
int z;
};
int main( int argc, char** argv )
{
printf( "A,C %d\n", (int)boost::is_virtual_base_of<A,C>::value );
printf( "B,C %d\n", (int)boost::is_virtual_base_of<B,C>::value );
printf( "A,D %d\n", (int)boost::is_virtual_base_of<A,D>::value );
printf( "virtual B,D %d\n", (int)boost::is_virtual_base_of<B,D>::value );
printf( "A,E %d\n", (int)boost::is_virtual_base_of<A,E>::value );
printf( "B,E %d\n", (int)boost::is_virtual_base_of<B,E>::value );
printf( "sizeof(A) %ld\n", sizeof(A) );
printf( "sizeof(B) %ld\n", sizeof(B) );
printf( "sizeof(C) %ld\n", sizeof(C) );
printf( "sizeof(D) %ld\n", sizeof(D) );
printf( "sizeof(E) %ld\n", sizeof(E) );
return 0;
}
================
A,C 0
B,C 0
A,D 1
virtual B,D 1
A,E 1
B,E 1
sizeof(A) 4
sizeof(B) 4
sizeof(C) 12
sizeof(D) 24
sizeof(E) 24
On Feb 11, 2010, at 12:59 PM, John Maddock wrote:
>> cast the bool to an int, still does not work. It works for most cases, for example this works:
>>
>> struct C : public A, public B
>> {
>> virtual test(); //
>> }
>>
>> struct C : public A, public B
>> {
>> virtual test();
>> float parameter; // DOESN"T WORK ANY MORE
>> };
>>
>
> Which specific compiler version? I need something that I can reproduce here... John.
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk