[clang] [clang-format] Detect language for file templates (PR #191502)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 13 23:08:39 PDT 2026


=?utf-8?q?Björn_Schäpers?= <bjoern at hazardy.de>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/191502 at github.com>


================
@@ -4427,7 +4427,13 @@ const char *StyleOptionHelpDescription =
     "4. \"{key: value, ...}\" to set specific parameters, e.g.:\n"
     "   --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
 
-static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
+static FormatStyle::LanguageKind getLanguageByFileName(StringRef &FileName) {
+  constexpr std::array TemplateSuffixes{llvm::StringLiteral{".in"},
+                                        llvm::StringLiteral{".template"}};
----------------
owenca wrote:

If you insist on using `std::array`, can you make it `static` and not reply on deduction guide?

```suggestion
  static constexpr std::array<StringRef, 2> TemplateSuffixes = {
      ".in",
      ".template",
  };
```
See existing `std::array` declarations in `FormatToken.cpp` and `NumericalLiteralCaseFixer.cpp`.

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


More information about the cfe-commits mailing list