Hello, i want to propose this check suggested by @EugeneZelenko.
I have found it in the beginner tag of llvm-bugzilla repository.
This check looks for numerical unsigned constants that are equal to -1 or ~0
and substitutes them with std::numeric_limits<type>::max().
It includes the library <limits> if is not found.
Example:
unsigned const int x = -1;
becomes
unsigned const int x = std::numeric_limits<unsigned int>::max();
If the library <limits> is not include in the TU the check will add it with this criteria:
- If a #include is found it will add #include <limits> before this include.
- if no #include directive is found it will add it at the begin of the TU.
I feel like the name is overly vague.
This *only* handles the cases of -1 and ~0.
It does not handle cases like 255 -> std::numeric_limits<uint_8>::max().
(It might be nice to do that, but it is more complex i suspect.)