[clang-tools-extra] [clang-doc] Migrate away from PointerUnion::{is,get} (NFC) (PR #120872)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 21 22:18:08 PST 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/120872

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>


>From 74f40fd73d831e46c782525e25fa4a8881a081dc Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 21 Dec 2024 21:42:41 -0800
Subject: [PATCH] [clang-doc] Migrate away from PointerUnion::{is,get} (NFC)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>
---
 clang-tools-extra/clang-doc/Serialize.cpp | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 93efdd44f45898..f737fc75135a19 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -696,13 +696,11 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber,
 
     // What this is a specialization of.
     auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
-    if (SpecOf.is<ClassTemplateDecl *>()) {
-      Specialization.SpecializationOf =
-          getUSRForDecl(SpecOf.get<ClassTemplateDecl *>());
-    } else if (SpecOf.is<ClassTemplatePartialSpecializationDecl *>()) {
-      Specialization.SpecializationOf =
-          getUSRForDecl(SpecOf.get<ClassTemplatePartialSpecializationDecl *>());
-    }
+    if (auto *CTD = dyn_cast<ClassTemplateDecl *>(SpecOf))
+      Specialization.SpecializationOf = getUSRForDecl(CTD);
+    else if (auto *CTPSD =
+                 dyn_cast<ClassTemplatePartialSpecializationDecl *>(SpecOf))
+      Specialization.SpecializationOf = getUSRForDecl(CTPSD);
 
     // Parameters to the specilization. For partial specializations, get the
     // parameters "as written" from the ClassTemplatePartialSpecializationDecl



More information about the cfe-commits mailing list