]> granicus.if.org Git - clang/commitdiff
[Sema] Don't crash when recovering from a misspelled pseudo destructor call to an...
authorBruno Ricci <riccibrun@gmail.com>
Thu, 24 Jan 2019 13:52:47 +0000 (13:52 +0000)
committerBruno Ricci <riccibrun@gmail.com>
Thu, 24 Jan 2019 13:52:47 +0000 (13:52 +0000)
When attempting to correct a misspelled pseudo destructor call as in:

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

a call is made in canRecoverDotPseudoDestructorCallsOnPointerObjects
to LookupDestructor without checking that the record has a definition.

This causes an assertion later in LookupSpecialMember which assumes that
the record has a definition.

Patch By Roman Zhikharevich!

Differential Revision: https://reviews.llvm.org/D57111

Reviewed By: riccibruno

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352047 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/incomplete-call.cpp

index d54696bbef7321eb66c3d2fa3f06dfe418370438..5ac248d36b413c60b93874b2504a9953e4aed5df 100644 (file)
@@ -6854,8 +6854,9 @@ canRecoverDotPseudoDestructorCallsOnPointerObjects(Sema &SemaRef,
                                                    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;
   }
 
index 6f5169ee8aa0528c59357296cf93188b48632c28..0fb1ef5f07a50e35f3b9d6cbbbe06db54ad0f879 100644 (file)
@@ -48,6 +48,10 @@ void test_incomplete_object_call(C& c) {
   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;