[Development] Q_DECLARE_TYPEINFO compile time checks

Marc Mutz marc.mutz at kdab.com
Mon Jul 27 15:28:41 CEST 2015


On Monday 27 July 2015 14:02:59 Curtis Mitch wrote:
> You mentioned that you have some kind of enforcement of the
> Q_DECLARE_TYPEINFO stuff - can you please share this so that others can
> run it on their modules?

It currently conflicts with Thiago's changes to add Q_RELOCATABLE_TYPE. I'll 
upstream parts of it that can be upstreamed once his stuff has merged, but the 
basic trick is:

- add isSpecialized = false to the primary QTypeInfo template
  ( = Q_IS_ENUM when Q_RELOCATABLE_TYPE lands)
- add isSpecialized = true to all specialisations
- static_assert that QTypeInfo<T>::isSpecialized in various places:
  * inside QVector::append
  * QList::node_construct
  * Q_DECLARE_METATPYE
  * whereever else it makes sense (I have the above three)

That doesn't catch all cases, of course, and it will not compile as long as 
QtCore hasn't been fully fixed (which requires Q_RELOCATABLE_TYPE), but we 
don't have a central macro that declares a type as a value type, so the three 
places above are the best I have come up with so far.

I'll upstream the addition of isSpecialized once Thiago's stuff is in. We 
should probably also change the Q_DECLARE_SHARED to be Q_DECLARE_VALUE_TYPE 
and _WITH_SWAP(). Then we have a central macro to put these checks, maybe just 
for headerscheck.

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts



More information about the Development mailing list