cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

enabled and fixed `-Wdouble-promotion` Clang warnings

Open firewave opened this issue 11 months ago • 5 comments

firewave avatar Jan 02 '25 15:01 firewave

Clang/GCC doesn't implement their checkers properly...

Code 1:

void dostuff(double x);

void f() {
    dostuff(0.1f);
}

Clang says:

test1.c:5:13: warning: implicit conversion increases floating-point precision: 'float' to 'double' [-Wdouble-promotion]

Code 2:

void dostuff(double x);

void f() {
    dostuff(static_cast<double>(0.1f));
}

.. after some time you have this ..

Code 3:

void dostuff(float x);

void f() {
    dostuff(static_cast<double>(0.1f));
}

And the compilers are silent about this. By turning on -Wdouble-promotion this is what you get. There was no problem in Code 1 but in Code 3 there is a performance problem. And it hurts the readability.

danmar avatar Jan 03 '25 09:01 danmar

Clang/GCC doesn't implement their checkers properly...

In that case please file an upstream report.

Looks like this might also be related to https://github.com/llvm/llvm-project/issues/93288.

firewave avatar Jan 03 '25 10:01 firewave

In that case please file an upstream report.

Nah, I doubt they would care about it.

danmar avatar Jan 05 '25 15:01 danmar

Nah, I doubt they would care about it.

Great attitude. Imagine people had the attitude towards false positives in Cppcheck.

Well, you might not imagine. They have that 100%. They just suppress the FP and if at some point there are too many suppressions or it gets too slow they just completely drop it completely because it "offers no value". That's how any tooling (not just open source) starts to deteriorate (even in cases where the devs actually care about the application and bug reports).

Well, they basically were too lazy to file a report and found me as the idiot which did their work for them because I cared.

That is actually the scenario because I got involved again because I wanted it to improve, so other people see that it actually has value and should be kept. See where that got me ...

And there has also been cases where people (including me) made something out to be a "false positive" but it turned out it was not and at the end you actually learned something new....

firewave avatar Jan 05 '25 15:01 firewave

Well, you might not imagine. They have that 100%.

Yes I have seen it myself also.

danmar avatar Jan 10 '25 17:01 danmar