[Interest] old style cast

Damian Ivanov damianatorrpm at gmail.com
Tue Aug 20 16:53:38 CEST 2019


Thank you for the tip Jérôme!

I will silence the warnings for that
https://forum.qt.io/topic/93238/disabling-compiler-warnings-in-creator-editor/12

Now I get that it the old style cast was about the "ay" to
GVariantType conversion, It would have been nice if QtCreator says
where it sees the cast issue,
I tried at some point     if (static_cast<bool>
(g_variant_is_of_type(value, G_VARIANT_TYPE_MAYBE))) which of course
is not related at all to the warning

On Tue, Aug 20, 2019 at 5:34 PM Jérôme Godbout <godboutj at amotus.ca> wrote:
>
> It's the macro G_VARIANT_TYPE_BYTESTRING itself that make the warning, you can either edit the macro or simply add one that would not do the C cast:
> (MyType)variable
> which is not really safe and have better alternative for C++, since the type is known a static_cast should be used instead:
> static_cast<MyType>(variable)
>
> #ifdef __cplusplus
> #define G_VARIANT_TYPE_BYTESTRING           (static_cast<const GVariantType *>("ay"))
> #else /* This is pure C implementation */
> #define G_VARIANT_TYPE_BYTESTRING           ((const GVariantType *) "ay")
> #endif
>
> Maybe this code is out of your reach (both usage and declaration and inside a lib that cannot be modified), at which point you will have to disable the warning at that particular place (sorry I don't known how to do this, since I normally fix the lib and never leave warning alive).
>
> -----Original Message-----
> From: Damian Ivanov <damianatorrpm at gmail.com>
> Sent: August 20, 2019 10:17 AM
> To: Jérôme Godbout <godboutj at amotus.ca>
> Cc: interest at qt-project.org
> Subject: Re: [Interest] old style cast
>
> but this is about G_VARIANT_TYPE_BYTESTRING which is #defined  in gvarianttype.h as commented in the original message and casting this has no effect:
> static_cast<const GVariantType *>(G_VARIANT_TYPE_BYTESTRING)
>
> On Tue, Aug 20, 2019 at 4:13 PM Jérôme Godbout <godboutj at amotus.ca> wrote:
> >
> > You should use static_cast instead of old C cast:
> > ((const GVariantType *) "ay")
> > should be
> > static_cast<const GVariantType *>("ay")
> >
> >
> > -----Original Message-----
> > From: Interest <interest-bounces at qt-project.org> On Behalf Of Damian
> > Ivanov
> > Sent: August 20, 2019 5:51 AM
> > To: interest at qt-project.org
> > Subject: [Interest] old style cast
> >
> > Hello,
> >
> > What is the correct way to do the following so it doesn't warn about the use of old stylecast?
> > //G_VARIANT_TYPE_BYTESTRING = is defined in gvarianttype.h
> > // #define G_VARIANT_TYPE_BYTESTRING           ((const GVariantType *) "ay")
> > // value is of type GVariant *value
> >
> > if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) // warn:
> > use of old style cast
> >
> > Thank you for suggestions.
> >
> > Regards,
> > Damian
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > https://lists.qt-project.org/listinfo/interest



More information about the Interest mailing list