[clang-tools-extra] [clangd] Omit C++ access specifiers from C hovers (PR #239877)

James Cowsert via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 7 14:49:41 PST 2026


================
@@ -666,7 +666,8 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
   HoverInfo HI;
   auto &Ctx = D->getASTContext();
 
-  HI.AccessSpecifier = getAccessSpelling(D->getAccess()).str();
+  if (Ctx.getLangOpts().CPlusPlus)
----------------
J-Cowsert wrote:

Objective-C++ sets `LangOpts.CPlusPlus` so the condition still passes and ordinary struct fields keep their access labels. That's not the case in Objective-C.

`@interface` ivars store their visibility separately. That viability is accessed through `ObjCIvarDecl::getAccessControl()` which Hover doesn't currently read. Their labels are omitted in both Objective-C and Objective-C++ and this patch preserves that behavior.

I've added tests covering both declaration types in both modes. 

55485733ec51d2f9e0d010174c87da45dc2026ef

https://github.com/llvm/llvm-project/pull/239877


More information about the cfe-commits mailing list