This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Can our C++ vectors hold derived classes?
- From: Andrew Pinski <pinskia at gmail dot com>
- To: GCC Mailing List <gcc at gcc dot gnu dot org>, Diego Novillo <dnovillo at google dot com>
- Date: Wed, 12 Jun 2013 14:27:46 -0700
- Subject: Re: Can our C++ vectors hold derived classes?
- References: <20130612172333 dot GG26236 at virgil dot suse>
On Wed, Jun 12, 2013 at 10:23 AM, Martin Jambor <mjambor@suse.cz> wrote:
> Hi everyone, but especially Diego :-)
>
> it seems to me that our new C++ vectors have some problems holding
> derived classes. For example, when try to compile the following
I think the answer is simple. vec supports POD only, once you have
inherents, it becomes non-POD in C++98.
Thanks,
Andrew Pinski
>
> struct zzzA
> {
> int kind;
> };
>
> struct zzzB : public zzzA
> {
> int some, data, here;
> };
>
> struct container
> {
> vec <zzzB> my_vec;
> };
> static struct container my_cnt;
>
> /* and then somewhere later do */
> my_cnt.my_vec.create (8);
>
> I get the following warnings:
>
> In file included from /home/mjambor/gcc/small/src/gcc/tree.h:27:0,
> from /home/mjambor/gcc/small/src/gcc/ipa-cp.c:106:
> /home/mjambor/gcc/small/src/gcc/vec.h: In instantiation of âstatic size_t vec<T, A, vl_embed>::embedded_size(unsigned int) [with T = zzzB; A = va_heap; size_t = long unsigned int]â:
> /home/mjambor/gcc/small/src/gcc/vec.h:298:64: required from âstatic void va_heap::reserve(vec<T, va_heap, vl_embed>*&, unsigned int, bool) [with T = zzzB]â
> /home/mjambor/gcc/small/src/gcc/vec.h:1468:5: required from âbool vec<T, A, vl_ptr>::reserve(unsigned int, bool) [with T = zzzB; A = va_heap]â
> /home/mjambor/gcc/small/src/gcc/vec.h:1482:45: required from âbool vec<T, A, vl_ptr>::reserve_exact(unsigned int) [with T = zzzB; A = va_heap]â
> /home/mjambor/gcc/small/src/gcc/vec.h:1497:5: required from âvoid vec<T, A, vl_ptr>::create(unsigned int) [with T = zzzB; A = va_heap]â
> /home/mjambor/gcc/small/src/gcc/ipa-cp.c:3608:26: required from here
> /home/mjambor/gcc/small/src/gcc/vec.h:1091:63: warning: invalid access to non-static data member âvec<zzzB, va_heap, vl_embed>::vecdata_â of NULL object [-Winvalid-offsetof]
> /home/mjambor/gcc/small/src/gcc/vec.h:1091:63: warning: (perhaps the âoffsetofâ macro was used incorrectly) [-Winvalid-offsetof]
> rm -rf libbackend.a
>
> Note that in the warning messages, the template parameters of vec
> change from (IMHO correct) vec<T, A, vl_ptr> to (IMHO wrong)
> vec<T, va_heap, vl_embed>.
>
> When I remove the ": public zzzA" part the earnings disappear. Thus,
> it seems there is an error somewhere... or am I doing something wrong?
>
> Thanks,
>
> Martin