[clang] Clang format numeric literal validity (PR #206516)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 26 13:00:41 PDT 2026
HazardyKnusperkeks wrote:
> > If you want to work on this, the fixer should check if this is currently an include statement or a macro invocation. Shouldn't be that hard and can definitely be two distinct PRs.
>
> It seems like macro invocation is difficult due to the fact that they can be defined in some other header file, e.g.
>
> ```
> // a.h
> #define FOO(x) foo##x
> ```
>
> ```
> // b.c
> #include "a.h"
> FOO(16header)
> ```
>
> Given that it currently formats the raw lexer output, how would it be able to deduce that FOO is a macro invocation when formatting b.c without recursively preprocessing includes? @HazardyKnusperkeks
We never parse `#define`s to store the definition or the name. Even because they can come from different files. But we have `FormatToken::isPossibleMacro`. And for everything else there is the `Macros` options (and many smaller flavors). But the `isPossibleMacro` function should apply to most real world scenarios.
https://github.com/llvm/llvm-project/pull/206516
More information about the cfe-commits
mailing list