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 @@ -282,6 +282,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); @@ -310,8 +311,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; @@ -333,7 +332,6 @@ } Completion.RequiredQualifier = std::string(ShortestQualifier); } - Completion.Deprecated |= (C.IndexResult->Flags & Symbol::Deprecated); } if (C.IdentifierResult) { Completion.Origin |= SymbolOrigin::Identifier; @@ -409,6 +407,14 @@ /*CommentsFromHeader=*/false)); } } + if (Completion.Deprecated) { + if (C.SemaResult) + Completion.Deprecated &= + C.SemaResult->Availability == CXAvailability_Deprecated; + if (C.IndexResult) + Completion.Deprecated &= + bool(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 @@ -1657,7 +1657,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); @@ -1695,6 +1695,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")));