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: Richard Biener <richard dot guenther at gmail dot com>
- To: GCC Mailing List <gcc at gcc dot gnu dot org>, Diego Novillo <dnovillo at google dot com>
- Date: Thu, 13 Jun 2013 10:12:08 +0200
- Subject: Re: Can our C++ vectors hold derived classes?
- References: <20130612172333 dot GG26236 at virgil dot suse>
On Wed, Jun 12, 2013 at 7:23 PM, 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
>
> 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?
I think you need to avoid using vl_embed vectors because their implementation
uses offsetof.
Richard.
> Thanks,
>
> Martin