[clang] [clang-format] Allow specifying the language for `.h` files (PR #128122)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 21 20:13:29 PST 2025


================
@@ -3353,7 +3353,12 @@ struct FormatStyle {
   }
   bool isTableGen() const { return Language == LK_TableGen; }
 
-  /// Language, this format style is targeted at.
+  /// The language that this format style targets.
+  /// \note
+  ///  You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
+  ///  by adding a ``// clang-format Language:`` line before the first
+  ///  non-comment and non-empty line, e.g. ``// clang-format Language: ObjC``.
----------------
owenca wrote:

Before first non-comment line:
```cpp
/// \version 20
// clang-format Language: ObjC

#ifndef FOO_H
```
Before first non-empty line:
```cpp
 
// clang-format Language: ObjC
/// \version 20
#ifndef FOO_H
```
Before first non-comment (and non-empty) line:
```cpp
/// \version 20

// clang-format Language: ObjC

#ifndef FOO_H
```
The latter basically means "before the first non-comment token".

https://github.com/llvm/llvm-project/pull/128122


More information about the cfe-commits mailing list