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

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@

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.

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.

    > 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.