diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -281,6 +281,7 @@ : ASTCtx(ASTCtx), EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets), IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) { + Completion.Deprecated = true; // cleared by any non-deprecated overload. add(C, SemaCCS); if (C.SemaResult) { assert(ASTCtx); @@ -309,8 +310,6 @@ return std::tie(X.range.start.line, X.range.start.character) < std::tie(Y.range.start.line, Y.range.start.character); }); - Completion.Deprecated |= - (C.SemaResult->Availability == CXAvailability_Deprecated); } if (C.IndexResult) { Completion.Origin |= C.IndexResult->Origin; @@ -332,7 +331,6 @@ } Completion.RequiredQualifier = std::string(ShortestQualifier); } - Completion.Deprecated |= (C.IndexResult->Flags & Symbol::Deprecated); } if (C.IdentifierResult) { Completion.Origin |= SymbolOrigin::Identifier; @@ -408,6 +406,12 @@ /*CommentsFromHeader=*/false)); } } + if (Completion.Deprecated) { + Completion.Deprecated = + (C.SemaResult && + C.SemaResult->Availability == CXAvailability_Deprecated) || + (C.IndexResult && C.IndexResult->Flags & Symbol::Deprecated); + } } CodeCompletion build() { diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -1644,7 +1644,7 @@ std::string Context = R"cpp( struct X { // Overload with int - int a(int); + int a(int) __attribute__((deprecated("", ""))); // Overload with bool int a(bool); int b(float); @@ -1682,6 +1682,7 @@ EXPECT_EQ(A.ReturnType, "int"); // All overloads return int. // For now we just return one of the doc strings arbitrarily. ASSERT_TRUE(A.Documentation); + ASSERT_FALSE(A.Deprecated); // Not all overloads deprecated. EXPECT_THAT( A.Documentation->asPlainText(), AnyOf(HasSubstr("Overload with int"), HasSubstr("Overload with bool")));