[clang-tools-extra] [clangd] added const and constexpr (PR #143193)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 6 12:31:35 PDT 2025


https://github.com/JohnFinn created https://github.com/llvm/llvm-project/pull/143193

None

>From 7104f44426829e4262851afdbe0182dcfe8da812 Mon Sep 17 00:00:00 2001
From: JohnFinn <dz4tune at gmail.com>
Date: Fri, 6 Jun 2025 21:28:12 +0200
Subject: [PATCH] [clangd] added const and constexpr

---
 .../clangd/HeaderSourceSwitch.cpp             | 26 ++++++++++---------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
index d54c3668570eb..ee4bea1401490 100644
--- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
+++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp
@@ -20,22 +20,24 @@ namespace clangd {
 
 std::optional<Path> getCorrespondingHeaderOrSource(
     PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
-  llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
-                                        ".c++", ".m", ".mm"};
-  llvm::StringRef HeaderExtensions[] = {".h",    ".hh",   ".hpp", ".hxx",
-                                        ".inc",  ".cppm", ".ccm", ".cxxm",
-                                        ".c++m", ".ixx"};
+  static constexpr llvm::StringRef SourceExtensions[] = {
+      ".cpp", ".c", ".cc", ".cxx", ".c++", ".m", ".mm"};
+  static constexpr llvm::StringRef HeaderExtensions[] = {
+      ".h",    ".hh",  ".hpp",  ".hxx",  ".inc",
+      ".cppm", ".ccm", ".cxxm", ".c++m", ".ixx"};
 
   llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);
 
   // Lookup in a list of known extensions.
-  bool IsSource = llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
-    return SourceExt.equals_insensitive(PathExt);
-  });
+  const bool IsSource =
+      llvm::any_of(SourceExtensions, [&PathExt](PathRef SourceExt) {
+        return SourceExt.equals_insensitive(PathExt);
+      });
 
-  bool IsHeader = llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
-    return HeaderExt.equals_insensitive(PathExt);
-  });
+  const bool IsHeader =
+      llvm::any_of(HeaderExtensions, [&PathExt](PathRef HeaderExt) {
+        return HeaderExt.equals_insensitive(PathExt);
+      });
 
   // We can only switch between the known extensions.
   if (!IsSource && !IsHeader)
@@ -94,7 +96,7 @@ std::optional<Path> getCorrespondingHeaderOrSource(PathRef OriginalFile,
   //
   // For each symbol in the original file, we get its target location (decl or
   // def) from the index, then award that target file.
-  bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
+  const bool IsHeader = isHeaderFile(OriginalFile, AST.getLangOpts());
   Index->lookup(Request, [&](const Symbol &Sym) {
     if (IsHeader)
       AwardTarget(Sym.Definition.FileURI);



More information about the cfe-commits mailing list