Skip to content

Commit 08c04ca

Browse files
committed
[clangd] Overload bundles are only deprecated if each overloads is.
Fixes clangd/clangd#705 Differential Revision: https://reviews.llvm.org/D97803
1 parent 7150b56 commit 08c04ca

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ struct CodeCompletionBuilder {
282282
: ASTCtx(ASTCtx),
283283
EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
284284
IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
285+
Completion.Deprecated = true; // cleared by any non-deprecated overload.
285286
add(C, SemaCCS);
286287
if (C.SemaResult) {
287288
assert(ASTCtx);
@@ -310,8 +311,6 @@ struct CodeCompletionBuilder {
310311
return std::tie(X.range.start.line, X.range.start.character) <
311312
std::tie(Y.range.start.line, Y.range.start.character);
312313
});
313-
Completion.Deprecated |=
314-
(C.SemaResult->Availability == CXAvailability_Deprecated);
315314
}
316315
if (C.IndexResult) {
317316
Completion.Origin |= C.IndexResult->Origin;
@@ -333,7 +332,6 @@ struct CodeCompletionBuilder {
333332
}
334333
Completion.RequiredQualifier = std::string(ShortestQualifier);
335334
}
336-
Completion.Deprecated |= (C.IndexResult->Flags & Symbol::Deprecated);
337335
}
338336
if (C.IdentifierResult) {
339337
Completion.Origin |= SymbolOrigin::Identifier;
@@ -409,6 +407,14 @@ struct CodeCompletionBuilder {
409407
/*CommentsFromHeader=*/false));
410408
}
411409
}
410+
if (Completion.Deprecated) {
411+
if (C.SemaResult)
412+
Completion.Deprecated &=
413+
C.SemaResult->Availability == CXAvailability_Deprecated;
414+
if (C.IndexResult)
415+
Completion.Deprecated &=
416+
bool(C.IndexResult->Flags & Symbol::Deprecated);
417+
}
412418
}
413419

414420
CodeCompletion build() {

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ TEST(CompletionTest, OverloadBundling) {
16571657
std::string Context = R"cpp(
16581658
struct X {
16591659
// Overload with int
1660-
int a(int);
1660+
int a(int) __attribute__((deprecated("", "")));
16611661
// Overload with bool
16621662
int a(bool);
16631663
int b(float);
@@ -1695,6 +1695,7 @@ TEST(CompletionTest, OverloadBundling) {
16951695
EXPECT_EQ(A.ReturnType, "int"); // All overloads return int.
16961696
// For now we just return one of the doc strings arbitrarily.
16971697
ASSERT_TRUE(A.Documentation);
1698+
ASSERT_FALSE(A.Deprecated); // Not all overloads deprecated.
16981699
EXPECT_THAT(
16991700
A.Documentation->asPlainText(),
17001701
AnyOf(HasSubstr("Overload with int"), HasSubstr("Overload with bool")));

0 commit comments

Comments
 (0)