[clang] 4075915 - [Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#124503)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 27 10:34:45 PST 2025


Author: Kazu Hirata
Date: 2025-01-27T10:34:41-08:00
New Revision: 4075915ebdfc7b69381388c96781e6abfa5f4407

URL: https://github.com/llvm/llvm-project/commit/4075915ebdfc7b69381388c96781e6abfa5f4407
DIFF: https://github.com/llvm/llvm-project/commit/4075915ebdfc7b69381388c96781e6abfa5f4407.diff

LOG: [Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#124503)

Note that PointerUnion::dyn_cast has 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>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect U.first to be nonnull.

Added: 
    

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 08065e3cad2bb3..c1a016ff91cb23 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9235,7 +9235,7 @@ struct SpecialMemberVisitor {
   static SourceLocation getSubobjectLoc(Subobject Subobj) {
     // FIXME: For an indirect virtual base, the direct base leading to
     // the indirect virtual base would be a more useful choice.
-    if (auto *B = Subobj.dyn_cast<CXXBaseSpecifier*>())
+    if (auto *B = dyn_cast<CXXBaseSpecifier *>(Subobj))
       return B->getBaseTypeLoc();
     else
       return cast<FieldDecl *>(Subobj)->getLocation();
@@ -17525,7 +17525,7 @@ DeclResult Sema::ActOnTemplatedFriendTag(
   unsigned FriendDeclDepth = TempParamLists.front()->getDepth();
   for (UnexpandedParameterPack &U : Unexpanded) {
     if (getDepthAndIndex(U).first >= FriendDeclDepth) {
-      auto *ND = U.first.dyn_cast<NamedDecl *>();
+      auto *ND = dyn_cast<NamedDecl *>(U.first);
       if (!ND)
         ND = cast<const TemplateTypeParmType *>(U.first)->getDecl();
       Diag(U.second, diag::friend_template_decl_malformed_pack_expansion)


        


More information about the cfe-commits mailing list