diff options
author | sstwcw <su3e8a96kzlver@posteo.net> | 2025-03-25 14:10:08 +0000 |
---|---|---|
committer | sstwcw <su3e8a96kzlver@posteo.net> | 2025-03-31 13:54:49 +0000 |
commit | ab7cee8a0ecf29fdb47c64c8d431a694d63390d2 (patch) | |
tree | bbb4e33de84efb96a2e09723d6266f2dc9337485 /clang/unittests/Format/FormatTestJava.cpp | |
parent | cb54026d92191e347629265d4082f5cc2cc28020 (diff) | |
download | llvm-ab7cee8a0ecf29fdb47c64c8d431a694d63390d2.zip llvm-ab7cee8a0ecf29fdb47c64c8d431a694d63390d2.tar.gz llvm-ab7cee8a0ecf29fdb47c64c8d431a694d63390d2.tar.bz2 |
[clang-format] Handle C++ keywords in other languages better (#132941)
There is some code to make sure that C++ keywords that are identifiers
in the other languages are not treated as keywords. Right now, the kind
is set to identifier, and the identifier info is cleared. The latter is
probably so that the code for identifying C++ structures does not
recognize those structures by mistake when formatting a language that
does not have those structures. But we did not find an instance where
the language can have the sequence of tokens, the code tries to parse
the structure as if it is C++ using the identifier info instead of the
token kind, but without checking for the language setting. However,
there are places where the code checks whether the identifier info field
is null or not. They are places where an identifier and a keyword are
treated the same way. For example, the name of a function in
JavaScript. This patch removes the lines that clear the identifier
info. This way, a C++ keyword gets treated in the same way as an
identifier in those places.
JavaScript
New
```JavaScript
async function
union(
myparamnameiswaytooloooong) {
}
```
Old
```JavaScript
async function
union(
myparamnameiswaytooloooong) {
}
```
Java
New
```Java
enum union { ABC, CDE }
```
Old
```Java
enum
union { ABC, CDE }
```
Diffstat (limited to 'clang/unittests/Format/FormatTestJava.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJava.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 33998bc..e01c1d6 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -158,6 +158,8 @@ TEST_F(FormatTestJava, AnonymousClasses) { TEST_F(FormatTestJava, EnumDeclarations) { verifyFormat("enum SomeThing { ABC, CDE }"); + // A C++ keyword should not mess things up. + verifyFormat("enum union { ABC, CDE }"); verifyFormat("enum SomeThing {\n" " ABC,\n" " CDE,\n" |