[cfe-dev] Missing -Wshorten-64-to-32 for operator+=

John McCall via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 27 21:04:22 PDT 2020


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
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list