[clang] [clang][ast][objc] Implement getNameForDiagnostic for ObjCMethodDecl and ObjCPropertyDecl. (PR #213030)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 31 07:19:20 PDT 2026


================
@@ -865,6 +865,24 @@ ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C,
                                     Selector(), QualType(), nullptr, nullptr);
 }
 
+void ObjCMethodDecl::getNameForDiagnostic(raw_ostream &OS,
+                                          const PrintingPolicy &Policy,
+                                          bool Qualified) const {
+  if (Qualified) {
+    OS << (isInstanceMethod() ? '-' : '+');
+    OS << '[';
+    if (const auto *ID = getClassInterface())
+      OS << ID->getName();
+    else if (const auto *PD = dyn_cast<ObjCProtocolDecl>(getDeclContext()))
+      OS << PD->getName();
+    else
+      OS << "<Unknown>";
----------------
dmaclach wrote:

I *believe* that the unknown branches are generally unreachable for valid, fully-formed AST nodes. I guess you could hit them in some incomplete state like deserialization, but that's a long shot. I'm not sure how to put together a test to exercise it, but thought that this was safer than asserting.

What would you prefer?

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


More information about the cfe-commits mailing list