Author: brunoricci Date: Thu Jan 24 05:52:47 2019 New Revision: 352047 URL: http://llvm.org/viewvc/llvm-project?rev=352047&view=rev Log: [Sema] Don't crash when recovering from a misspelled pseudo destructor call to an incomplete type.
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 Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/test/SemaCXX/incomplete-call.cpp Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=352047&r1=352046&r2=352047&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Jan 24 05:52:47 2019 @@ -6854,8 +6854,9 @@ canRecoverDotPseudoDestructorCallsOnPoin 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; } Modified: cfe/trunk/test/SemaCXX/incomplete-call.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/incomplete-call.cpp?rev=352047&r1=352046&r2=352047&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/incomplete-call.cpp (original) +++ cfe/trunk/test/SemaCXX/incomplete-call.cpp Thu Jan 24 05:52:47 2019 @@ -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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits