[clang] fbe0ca5 - [clang][sema] checkNoThrow - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 12 03:19:04 PST 2022


Author: Simon Pilgrim
Date: 2022-02-12T11:18:49Z
New Revision: fbe0ca576d2b96c523182200529b5afbf709506f

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

LOG: [clang][sema] checkNoThrow - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    clang/lib/Sema/SemaCoroutine.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index aae90c403f0f..71fcf4aebda8 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -680,7 +680,7 @@ static void checkNoThrow(Sema &S, const Stmt *E,
         QualType::DestructionKind::DK_cxx_destructor) {
       const auto *T =
           cast<RecordType>(ReturnType.getCanonicalType().getTypePtr());
-      checkDeclNoexcept(dyn_cast<CXXRecordDecl>(T->getDecl())->getDestructor(),
+      checkDeclNoexcept(cast<CXXRecordDecl>(T->getDecl())->getDestructor(),
                         /*IsDtor=*/true);
     }
   } else


        


More information about the cfe-commits mailing list