[clang-tools-extra] [clang-tidy] Add portability-avoid-platform-specific-fundamental-types (PR #146970)
JJ Marr via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 4 14:52:12 PDT 2025
jj-marr wrote:
> Check makes sense to me! As a first iteration it's fine without autofix but I can imagine it will be hard for a codebase to enable this check given the large amount of things to fix. Maybe users can specify a mapping of wanted types via an option?
I'm planning for an autofix of `float` and `double` since it's unambiguous what those types should be.
For `int` types, maybe I'll give 3 options for an autofix:
* Fixed (`int32_t`)
* Fast (`int_fast32_t`)
* Least (`int_least32_t`)
Based on sizeof the type when running `clang-tidy`. This represents compatibility/time/space tradeoffs.
Not sure about `char`. If you're actually representing UTF-8 text, it's a good idea to replace with `char8_t`. If you're using `char` because it's 1 byte and you want to do wacky things with memory, `std::byte` is the way to go. I'm not sure how relatively common each is since I work with low-level hardware at my day job and I'm biased towards assuming weird byte level stuff is more common than it really is.
It's also not a "safe" replacement to get rid of `char` in all cases, since `char8_t` and `std::byte` are always unsigned. If the memory representation of `char` is identical to `unsigned char` it's probably safe enough?
https://github.com/llvm/llvm-project/pull/146970
More information about the cfe-commits
mailing list