[clang-tools-extra] [clang-tidy] warn when `true` is used as a preprocessor keyword in C (PR #128265)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 28 18:09:57 PST 2025
zygoloid wrote:
> > 2. Create check that forbids usage of true/false in processor as an non-portable thing (could be in portability category)
> > 3. Extracting 'true' case from -Wundef into separate warning like -Wundef-true
>
> I like both of these approaches, though I prefer the 2. one because even if we extract `-Wundef-true`, `gcc` won't have the same option.
That's true, but somewhat irrelevant, especially if we enable `-Wundef-true` in clang by default.
Clang-tidy uses clang to process the source file, so any warning implemented in clang is available to all clang-tidy users regardless of whether they compile with clang or GCC or something else. So if we implement this in clang, then any clang user gets the warning, and any clang-tidy user gets the warning too (even if they compile with GCC). But if we implement it in clang-tidy, then clang users who don't use clang-tidy only get the warning if they enable `-Wundef`, which is less useful and probably not something people can realistically enable. So it's no worse for any user, and better for some, to implement this as a compiler warning. And that's the right place for it anyway.
https://github.com/llvm/llvm-project/pull/128265
More information about the cfe-commits
mailing list