[PATCH] D135254: [clang][Sema] Fix crash on invalid base destructor

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 5 06:10:41 PDT 2022


hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

looks good, Sema::LookupDefaultConstructor already does the similar thing as well.



================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:5699
     CXXDestructorDecl *Dtor = LookupDestructor(BaseClassDecl);
-    assert(Dtor && "No dtor found for BaseClassDecl!");
+    // Dtor might still be missing, e.g because it's invalid.
+    if (!Dtor)
----------------
I think we should do similar change on L5699, L5736 as well.


================
Comment at: clang/lib/Sema/SemaLookup.cpp:3620
 CXXDestructorDecl *Sema::LookupDestructor(CXXRecordDecl *Class) {
-  return cast<CXXDestructorDecl>(LookupSpecialMember(Class, CXXDestructor,
-                                                     false, false, false,
-                                                     false, false).getMethod());
+  return llvm::cast_or_null<CXXDestructorDecl>(
+      LookupSpecialMember(Class, CXXDestructor, false, false, false, false,
----------------
nit: the prefix `llvm::` can be eliminated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135254/new/

https://reviews.llvm.org/D135254



More information about the cfe-commits mailing list