[clang-tools-extra] [clangd] added const and constexpr (PR #143193)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 6 12:32:29 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-clangd
Author: Jouni (JohnFinn)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/143193.diff
1 Files Affected:
- (modified) clang-tools-extra/clangd/HeaderSourceSwitch.cpp (+14-12)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/143193
More information about the cfe-commits
mailing list