https://github.com/hongtaihu updated 
https://github.com/llvm/llvm-project/pull/212134

>From edc94e59d2bff3dea73602bc2ce232c47c588efe Mon Sep 17 00:00:00 2001
From: hongtaihu <[email protected]>
Date: Mon, 27 Jul 2026 01:07:59 +0800
Subject: [PATCH] [clangd] Avoid invalid include-fixer fuzzy-find queries

---
 clang-tools-extra/clangd/IncludeFixer.cpp           |  8 +++++++-
 .../clangd/unittests/DiagnosticsTests.cpp           | 13 +++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp 
b/clang-tools-extra/clangd/IncludeFixer.cpp
index 5ecf853524a3f..0cd5b5c23bfba 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -397,8 +397,14 @@ std::optional<std::string> getSpelledSpecifier(const 
CXXScopeSpec &SS,
 std::optional<CheapUnresolvedName> extractUnresolvedNameCheaply(
     const SourceManager &SM, const DeclarationNameInfo &Unresolved,
     CXXScopeSpec *SS, const LangOptions &LangOpts, bool UnresolvedIsSpecifier) 
{
+  // IncludeFixer looks up a simple identifier and resolves its scope
+  // independently. DeclarationNameInfo may also describe special names, such
+  // as a conversion function, which cannot be represented this way.
+  if (!Unresolved.getName().isIdentifier())
+    return std::nullopt;
+
   CheapUnresolvedName Result;
-  Result.Name = Unresolved.getAsString();
+  Result.Name = Unresolved.getName().getAsIdentifierInfo()->getName();
   if (SS && SS->isNotEmpty()) { // "::" or "ns::"
     NestedNameSpecifier Nested = SS->getScopeRep();
     if (Nested.getKind() == NestedNameSpecifier::Kind::Global) {
diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 6d91ac1ef1e8e..cb1612fbd318b 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1560,6 +1560,19 @@ TEST(IncludeFixerTest, NoCrashMemberAccess) {
       UnorderedElementsAre(Diag(Test.range(), "no member named 'xy' in 'X'")));
 }
 
+TEST(IncludeFixerTest, IgnoreSpecialDeclarationName) {
+  auto TU = TestTU::withCode(R"cpp(// error-ok
+namespace std {}
+void f() { operator new[](0, operator::align_val_t{}); }
+  )cpp");
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto Index = buildIndexWithSymbol(
+      SymbolWithHeader{"std::align_val_t", "unittest:///new.h", "<new>"});
+  TU.ExternalIndex = Index.get();
+
+  EXPECT_THAT(TU.build().getDiagnostics(), Not(IsEmpty()));
+}
+
 TEST(IncludeFixerTest, UseCachedIndexResults) {
   // As index results for the identical request are cached, more than 5 fixes
   // are generated.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to