[cfe-dev] Warnings about automatic demotion in implicit casts?
neil at daikokuya.co.uk
Tue Aug 26 08:08:12 PDT 2008
Nikita Zhuk wrote:-
> 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.
More information about the cfe-dev