[PATCH] D57111: Make Clang not crash on calls to destructors on incomplete pointer types

Roman Zhikharevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 23 11:54:31 PST 2019


rzhikharevich created this revision.
rzhikharevich added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes handling of code like this:

  c++
  struct Foo;
  
  void foo(Foo *p) {
    p.~Foo();
  }


Repository:
  rC Clang

https://reviews.llvm.org/D57111

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/incomplete-call.cpp


Index: clang/test/SemaCXX/incomplete-call.cpp
===================================================================
--- clang/test/SemaCXX/incomplete-call.cpp
+++ clang/test/SemaCXX/incomplete-call.cpp
@@ -48,6 +48,10 @@
   c(); // expected-error{{incomplete type in call to object of type}}
 }
 
+void test_incomplete_object_dtor(C *p) {
+  p.~C(); // expected-error{{member reference type 'C *' is a pointer; did you mean to use '->'?}}
+}
+
 namespace pr18542 {
   struct X {
     int count;
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -6854,8 +6854,9 @@
                                                    QualType DestructedType) {
   // If this is a record type, check if its destructor is callable.
   if (auto *RD = DestructedType->getAsCXXRecordDecl()) {
-    if (CXXDestructorDecl *D = SemaRef.LookupDestructor(RD))
-      return SemaRef.CanUseDecl(D, /*TreatUnavailableAsInvalid=*/false);
+    if (RD->hasDefinition())
+      if (CXXDestructorDecl *D = SemaRef.LookupDestructor(RD))
+        return SemaRef.CanUseDecl(D, /*TreatUnavailableAsInvalid=*/false);
     return false;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57111.183144.patch
Type: text/x-patch
Size: 1229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190123/84310b63/attachment-0001.bin>


More information about the cfe-commits mailing list