[all-commits] [llvm/llvm-project] ed8582: [clang-format] Handle C++ keywords in other langua...

sstwcw via All-commits all-commits at lists.llvm.org
Thu Apr 10 05:51:31 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ed858220276dd11f6c2d7a5d3e357c211f9c6190
      https://github.com/llvm/llvm-project/commit/ed858220276dd11f6c2d7a5d3e357c211f9c6190
  Author: sstwcw <su3e8a96kzlver at posteo.net>
  Date:   2025-04-10 (Thu, 10 Apr 2025)

  Changed paths:
    M clang/lib/Format/FormatTokenLexer.cpp
    M clang/unittests/Format/FormatTestJS.cpp
    M clang/unittests/Format/FormatTestJava.cpp

  Log Message:
  -----------
  [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 }
```

This reverts commit 97dcbdef6089175c45e14fcbcf5c88b10233a79a.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list