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

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 31 08:15:55 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>";
----------------
steakhal wrote:

Alright. I think I'd prefer clearly documenting what branches are feasible and which are not.
Put an `assert(false)` to the branches that are provably infeasible for valid C++ but handle the situation gracefully to make release builds work without assertions.
If anyone trips on the assert in debug, they should have a clear idea what went wrong, like we clearly violated some invariant to get here with an illformed AST node.

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


More information about the cfe-commits mailing list