Warnings about automatic demotion in implicit casts?

Hi,

Are there any plans to include an option to generate warnings of implicit casts which cause automatic demotion (and may thus result in loss of information)? For example, the following code doesn't currently produce any warnings in clang (gcc with -Wall -pedantic doesn't produce any warnings either):

char c = 0; int i = 0; long long ll = 0; float f = 0.0; double d = 0.0;
c = i; c = ll; c = f; c = d;
i = ll; i = f; i = d;
ll = f; ll = d;
f = d;

It would be beneficial to get warnings of all implicit casts which cause automatic demotion: in assignments, comparisons, function/method parameters and return values. Would this cause too much false positives? Should I file a feature request?

- Nikita

Nikita Zhuk wrote:-

Hi,

Are there any plans to include an option to generate warnings of
implicit casts which cause automatic demotion (and may thus result in
loss of information)? For example, the following code doesn't
currently produce any warnings in clang (gcc with -Wall -pedantic
doesn't produce any warnings either):

char c = 0; int i = 0; long long ll = 0; float f = 0.0; double d = 0.0;
c = i; c = ll; c = f; c = d;
i = ll; i = f; i = d;
ll = f; ll = d;
f = d;

It would be beneficial to get warnings of all implicit casts which
cause automatic demotion: in assignments, comparisons, function/method
parameters and return values. Would this cause too much false
positives? Should I file a feature request?

Such a diagnostic is reasonable, but you also need to give a
reasonable testcase. Front ends are getting smarter, particularly
at trying to avoid noise, which it would be in your case where no
demotion is actually occurring. It is not hard to avoid diagnosing
your example even if the compiler diagnoses them in general.

Neil.

It would be very nice to add something like this. If you're interested, I'd suggest following the lead of the -Wcoercion option recently added to GCC mainline:
http://gcc.gnu.org/wiki/Wcoercion

-Chris