[clang-tidy] UseDefaultMemberInitCheck::checkDefaultInit - Use cast<> instead of...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 12 Jan 2022 15:03:09 +0000 (15:03 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 12 Jan 2022 15:35:37 +0000 (15:35 +0000)
The pointer is always dereferenced immediately below, so assert the cast is correct instead of returning nullptr

clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

index d57a88d..6f8c984 100644 (file)
@@ -247,7 +247,7 @@ void UseDefaultMemberInitCheck::checkDefaultInit(
 
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
-  const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Field->getParent());
+  const auto *ClassDecl = cast<CXXRecordDecl>(Field->getParent());
   if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
         return !Ctor->isCopyOrMoveConstructor();
       }) > 1)