qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC v2 0/9] qom: Make object_get_class()/*_GET_CLASS r


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [RFC v2 0/9] qom: Make object_get_class()/*_GET_CLASS return const pointers
Date: Sun, 2 Apr 2017 10:31:53 -0300
User-agent: Mutt/1.7.1 (2016-10-04)

On Thu, Mar 30, 2017 at 10:59:10AM +0200, Paolo Bonzini wrote:
[...]
> That said, the QUALIFIED_CAST concept is very interesting and I'd even
> extend it to OBJECT_CHECK, object_dynamic_cast and
> object_dynamic_cast_assert.  I'm just not sure about returning const
> from object_get_class()/*_GET_CLASS, which ironically is the thing that
> prompted you to write the series. :)

When trying to change OBJECT and OBJECT_CHECK, I've found a
problem: gcc 6.2.1 can't evaluate typeof(*a) if *a has an
incomplete type, even inside the (const typeof(*(t)0) *)
expression used in QUALIFIED_CAST. It works on clang, though.

I'm not sure we want to introduce something that would report
errors only on clang only[1]. Especially when the error messages
look like this:
  hw/mem/pc-dimm.c:248:23: error: passing 'typeof (_Generic((const typeof 
(*((typeof ((a)))0)) *)0, typeof ((a)): (const Object *)(0), default: (Object 
*)(0)))' (aka 'const struct Object *') to parameter of type 'Object *' (aka 
'struct Object *') discards qualifiers 
[-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      PCDIMMDevice *x = PC_DIMM(a);

Lucikly all the OBJECT_CLASS usage I've found never involved
incomplete types, but they are more common when dealing with
object pointers.

We could also require all users of OBJECT(x) to include the
header that defines the struct type of x. But I'm not sure it's
worth the effort.

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]