Background: I try to force the developer to append a "F" as suffix for float constants declarations e.g. 1.0 -> 1.0F or 2.0f -> 2.0F. The first case will force the use of the FPU the latter for uniformity with U and L suffixes.
I detected the following but realized that using token.isFloat to check if a token is of type float, works perfectly. But I will keep my findings anyway for someone of interest. When I first wrote the addon I may misunderstood the ast-part and misused cppcheckdata.astIsFloat(token) for my case. Maybe the following is a feature and no issue at all:
I usedif cppcheckdata.astIsFloat(token) and not token.variable: to check if a constant type declaration is of type float.
It worked quite reliable but I was confused to find UCHAR_MAX in the findings. It is defined as #define UCHAR_MAX 0xff and should have nothing to do with float. I investigated that all variables with an f will return true if checked with cppcheckdata.astIsFloat(token).
Background: I try to force the developer to append a "F" as suffix for float constants declarations e.g. 1.0 -> 1.0F or 2.0f -> 2.0F. The first case will force the use of the FPU the latter for uniformity with U and L suffixes.
I detected the following but realized that using
token.isFloat
to check if a token is of type float, works perfectly. But I will keep my findings anyway for someone of interest. When I first wrote the addon I may misunderstood theast
-part and misusedcppcheckdata.astIsFloat(token)
for my case. Maybe the following is a feature and no issue at all:I used
if cppcheckdata.astIsFloat(token) and not token.variable:
to check if a constant type declaration is of type float.It worked quite reliable but I was confused to find
UCHAR_MAX
in the findings. It is defined as#define UCHAR_MAX 0xff
and should have nothing to do with float. I investigated that all variables with anf
will return true if checked withcppcheckdata.astIsFloat(token)
.Test with:
The problem is the implementation in cppcheckdata.py of the check with:
More valid floats falsely not detected:
1e10
,0X0p-1
,0x0P-1
Also:
if token.str[0].isdigit():
will result in all token of valid negative floats not getting detected.FYI: https://clang.llvm.org/extra/clang-tidy/checks/readability/uppercase-literal-suffix.html