Missing -Wshorten-64-to-32 for operator+=

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Missing -Wshorten-64-to-32 for operator+=

Keane, Erich via cfe-dev
Hi,

I have found that operator+= doesn't fire -Wshorten-64-to-32 warning, while pure opreator+ fires it. See the
following example:

#include <stdint.h>

int main()
{
     uint32_t test = 0;
     uint64_t test64 = UINT32_MAX + 1;
     test += test64;// doesn't fire the warning
     test = test + test64; // fires the warning: implicit conversion loses integer precision: 'unsigned long' to
'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32]
}

I've found this in 32-bit build while adding uint64_t to size_t (size_t has 4 byte on 32-bit) variable (Clang
didn't warn me while MSVC surprisingly did :-)).

Should I post a bug-report or is it some known exception where the warning should not occur?

Mi-L@



_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

smime.p7s (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Missing -Wshorten-64-to-32 for operator+=

Keane, Erich via cfe-dev
On 24 Jul 2020, at 5:04, Milan Kříž via cfe-dev wrote:

> Hi,
>
> I have found that operator+= doesn't fire -Wshorten-64-to-32 warning,
> while pure opreator+ fires it. See the following example:
>
> #include <stdint.h>
>
> int main()
> {
>     uint32_t test = 0;
>     uint64_t test64 = UINT32_MAX + 1;
>     test += test64;// doesn't fire the warning
>     test = test + test64; // fires the warning: implicit conversion
> loses integer precision: 'unsigned long' to 'uint32_t' (aka 'unsigned
> int') [-Wshorten-64-to-32]
> }
>
> I've found this in 32-bit build while adding uint64_t to size_t
> (size_t has 4 byte on 32-bit) variable (Clang didn't warn me while
> MSVC surprisingly did :-)).
>
> Should I post a bug-report or is it some known exception where the
> warning should not occur?

Please file a bug.  There’s no reason for the warning to not fire on
compound operators like it would on the expanded form.

John.

>
> Mi-L@
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Missing -Wshorten-64-to-32 for operator+=

Keane, Erich via cfe-dev
I'd filed https://bugs.llvm.org/show_bug.cgi?id=33559 for this quite a while back, although I never got the chance to look into it more.

On 7/27/20, 9:04 PM, "cfe-dev on behalf of John McCall via cfe-dev" <[hidden email] on behalf of [hidden email]> wrote:

    On 24 Jul 2020, at 5:04, Milan Kříž via cfe-dev wrote:
    > Hi,
    >
    > I have found that operator+= doesn't fire -Wshorten-64-to-32 warning,
    > while pure opreator+ fires it. See the following example:
    >
    > #include <stdint.h>
    >
    > int main()
    > {
    >     uint32_t test = 0;
    >     uint64_t test64 = UINT32_MAX + 1;
    >     test += test64;// doesn't fire the warning
    >     test = test + test64; // fires the warning: implicit conversion
    > loses integer precision: 'unsigned long' to 'uint32_t' (aka 'unsigned
    > int') [-Wshorten-64-to-32]
    > }
    >
    > I've found this in 32-bit build while adding uint64_t to size_t
    > (size_t has 4 byte on 32-bit) variable (Clang didn't warn me while
    > MSVC surprisingly did :-)).
    >
    > Should I post a bug-report or is it some known exception where the
    > warning should not occur?

    Please file a bug.  There’s no reason for the warning to not fire on
    compound operators like it would on the expanded form.

    John.

    >
    > Mi-L@
    >
    >
    > _______________________________________________
    > cfe-dev mailing list
    > [hidden email]
    > https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Ddev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=VVQZ_VwovdijqjDSZNSKTp9kTFWVSYtl0iTOKmzW16k&s=8pN4RKYZ5W9xgZveUXhjilV-AAJWYtZRKese1aALS8A&e= 
    _______________________________________________
    cfe-dev mailing list
    [hidden email]
    https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Ddev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=VVQZ_VwovdijqjDSZNSKTp9kTFWVSYtl0iTOKmzW16k&s=8pN4RKYZ5W9xgZveUXhjilV-AAJWYtZRKese1aALS8A&e= 

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev