[clang] [clang-format] Add space after a word token (PR #92741)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Tue May 21 12:21:07 PDT 2024
HazardyKnusperkeks wrote:
> > Since I am by no means an expert on Clang, a few questions arose
> >
> > * As Clang formats the code correctly (no code changes necessary) when instead of `xor` a different function name e.g. `xooor` is used, I wonder why `xor` is tokenized as Unary operator in the first place in C?
> > * Is C and C++ using the same tokenizations?
>
> clang-format formats all C code as C++. Since `xor` is a C++ keyword, it's lexed as `tok::caret`, which is then erroneously annotated as `TT_UnaryOperator`. This bug was uncovered by #90161.
>
> > * How to properly distinguish between the C and C++ language in Clang Format?
>
> clang-format can't do it properly. @mydeveloperday, @HazardyKnusperkeks, and @rymiel may know more about why we didn't add `LK_C` to the [`Language`](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#language) option.
If I remember correctly, I was in favor of adding a C language.
> Because if this code was in a .h and not a .c you wouldn't know what language you were in
There are certainly headers which are ambiguous, and we could add an option to set the language of such headers. But if we hit a `class`, `namespace`, or a `::` we could fairly certain use it as C++ header. Similar to `guessIsObjC`, and skip checking for C++ if the new option is set to C++ (which of course would be the default, to keep existing behavior).
https://github.com/llvm/llvm-project/pull/92741
More information about the cfe-commits
mailing list