diff --git a/clang/lib/Sema/UsedDeclVisitor.h b/clang/lib/Sema/UsedDeclVisitor.h index c33d30478e2ab..24b7342b3fb40 100644 --- a/clang/lib/Sema/UsedDeclVisitor.h +++ b/clang/lib/Sema/UsedDeclVisitor.h @@ -72,7 +72,8 @@ class UsedDeclVisitor : public EvaluatedExprVisitor { QualType Destroyed = S.Context.getBaseElementType(DestroyedOrNull); if (const RecordType *DestroyedRec = Destroyed->getAs()) { CXXRecordDecl *Record = cast(DestroyedRec->getDecl()); - asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record)); + if (Record->getDefinition()) + asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record)); } } diff --git a/clang/test/OpenMP/deferred-diags.cpp b/clang/test/OpenMP/deferred-diags.cpp index 037498b7fedbf..0c38e68ae81ab 100644 --- a/clang/test/OpenMP/deferred-diags.cpp +++ b/clang/test/OpenMP/deferred-diags.cpp @@ -6,8 +6,6 @@ // RUN: -verify-ignore-unexpected=note \ // RUN: -fopenmp -o - %s -// expected-no-diagnostics - // Test no infinite recursion in DeferredDiagnosticEmitter. constexpr int foo(int *x) { return 0; @@ -37,3 +35,14 @@ class A : public B { } } }; + +// Test that deleting an incomplete class type doesn't cause an assertion. +namespace TestDeleteIncompleteClassDefinition { +struct a; +struct b { + b() { + delete c; // expected-warning {{deleting pointer to incomplete type 'TestDeleteIncompleteClassDefinition::a' may cause undefined behavior}} + } + a *c; +}; +} // namespace TestDeleteIncompleteClassDefinition