[clang] 77f4160 - [clangd] fixed signature help for c++23 static () operator (#234918)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 3 02:01:23 PST 2026
Author: Daniel Aviv
Date: 2026-11-03T11:01:18+01:00
New Revision: 77f4160ca5ad9a207d8b1ef4d6aa21a33be24ad1
URL: https://github.com/llvm/llvm-project/commit/77f4160ca5ad9a207d8b1ef4d6aa21a33be24ad1
DIFF: https://github.com/llvm/llvm-project/commit/77f4160ca5ad9a207d8b1ef4d6aa21a33be24ad1.diff
LOG: [clangd] fixed signature help for c++23 static () operator (#234918)
Signature help can fail to display signatures for C++23 static
`operator()` overloads,
with inconsistent behavior for templated operators.
Pass `FirstArgumentIsBase=true` when building overload candidates for
call signature help so the object argument is handled correctly for
static call operators.
Add regression coverage for static and templated static call operators
with one and two parameters, checking both the displayed signatures
and the active parameter.
Fixes #196153.
Added:
Modified:
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/lib/Sema/SemaCodeComplete.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index edfd29136881fd..01cf85ce9f1577 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3529,6 +3529,67 @@ TEST(SignatureHelpTest, VariadicType) {
}
}
+TEST(SignatureHelpTest, StaticCallOperator) {
+ Annotations Code(R"cpp(
+ struct A { static void operator()(bool a); };
+ struct B { static void operator()(bool a, bool b); };
+ struct C { template <typename T> static void operator()(T a); };
+ struct D { template <typename T> static void operator()(T a, bool b); };
+ void test() {
+ A{}($a^);
+ B{}($b^);
+ B{}(true, $b2^);
+ C{}($c^);
+ D{}($d^);
+ D{}(true, $d2^);
+ B::operator()($static^);
+ B::operator()(true, $static2^);
+ D::operator()($staticTemplate^);
+ D::operator()(true, $staticTemplate2^);
+ auto Lambda = [](bool a, bool b) static {};
+ Lambda($lambda^);
+ Lambda(true, $lambda2^);
+ auto GenericLambda = []<typename T>(T a, bool b) static -> void {};
+ GenericLambda($genericLambda^);
+ GenericLambda(true, $genericLambda2^);
+ }
+ )cpp");
+ auto TU = TestTU::withCode(Code.code());
+ TU.ExtraArgs = {"-std=c++23"};
+ MockFS FS;
+ auto Inputs = TU.inputs(FS);
+ auto Preamble = TU.preamble();
+ ASSERT_TRUE(Preamble);
+
+ const struct {
+ const char *Point;
+ const char *Signature;
+ int ActiveParameter;
+ } Cases[] = {
+ {"a", "operator()([[bool a]]) -> void", 0},
+ {"b", "operator()([[bool a]], [[bool b]]) -> void", 0},
+ {"b2", "operator()([[bool a]], [[bool b]]) -> void", 1},
+ {"c", "operator()([[T a]]) -> void", 0},
+ {"d", "operator()([[T a]], [[bool b]]) -> void", 0},
+ {"d2", "operator()([[T a]], [[bool b]]) -> void", 1},
+ {"static", "operator()([[bool a]], [[bool b]]) -> void", 0},
+ {"static2", "operator()([[bool a]], [[bool b]]) -> void", 1},
+ {"staticTemplate", "operator()([[T a]], [[bool b]]) -> void", 0},
+ {"staticTemplate2", "operator()([[T a]], [[bool b]]) -> void", 1},
+ {"lambda", "operator()([[bool a]], [[bool b]]) -> void", 0},
+ {"lambda2", "operator()([[bool a]], [[bool b]]) -> void", 1},
+ {"genericLambda", "operator()([[T a]], [[bool b]]) -> void", 0},
+ {"genericLambda2", "operator()([[T a]], [[bool b]]) -> void", 1},
+ };
+ for (const auto &Case : Cases) {
+ SCOPED_TRACE(Case.Point);
+ auto Result = signatureHelp(testPath(TU.Filename), Code.point(Case.Point),
+ *Preamble, Inputs, MarkupKind::PlainText);
+ EXPECT_THAT(Result.signatures, ElementsAre(sig(Case.Signature)));
+ EXPECT_EQ(Case.ActiveParameter, Result.activeParameter);
+ }
+}
+
TEST(SignatureHelpTest, SkipExplicitObjectParameter) {
Annotations Code(R"cpp(
struct A {
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 2e852281395280..727933f7d7195f 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6567,7 +6567,8 @@ SemaCodeCompletion::ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args,
CandidateSet,
/*ExplicitArgs=*/nullptr,
/*SuppressUserConversions=*/false,
- /*PartialOverloading=*/true);
+ /*PartialOverloading=*/true,
+ /*FirstArgumentIsBase=*/true);
}
} else {
// Lastly we check whether expression's type is function pointer or
More information about the cfe-commits
mailing list