[cfe-dev] 64 to 32 truncation warnings for ints and floats?
John McCall
rjmccall at apple.com
Fri Nov 12 10:25:38 PST 2010
On Nov 12, 2010, at 8:50 AM, Sean McBride wrote:
> In C & C++, Apple's gcc 4.2 produces 2 warnings for this code with -
> Wshorten-64-to-32:
>
> int main(int,char**)
> {
> double d = 1.0;
> float f = d; // warning: 64 to 32
>
> long s1 = 10;
> long s2 = 20;
> int diff = s2 - s1; // warning: 64 to 32
>
> return 0;
> }
>
> clang (trunk) only warns for the integer case. Is there a way to get
> warnings for the double->float conversion too?
The generic "warn about any implicit conversions that might lose precision"
warning is -Wconversion. Clang's implementation of that is similar to
gcc-4.3's, i.e. substantially better than gcc-4.2's.
-Wshorten-64-to-32 was never supposed to be more than a portability
warning, which is why I didn't warn about double->float in clang's
implementation. Note that -Wshorten-64-to-32 is implied by -Wconversion.
John.
More information about the cfe-dev
mailing list