From: Nico Weber Date: Fri, 6 Mar 2015 06:01:06 +0000 (+0000) Subject: Don't crash on non-public referenced dtors in toplevel classes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c273334603c27e427c7811225a1aaf61e6e3be96;p=clang Don't crash on non-public referenced dtors in toplevel classes. Fixes PR22793, a bug that caused self-hosting to fail after the innocuous r231254. See the bug for details. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231451 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 3725b2d1f3..84315be781 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -117,7 +117,7 @@ static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S, case AR_Available: case AR_NotYetIntroduced: break; - + case AR_Deprecated: if (S.getCurContextAvailability() != AR_Deprecated) S.EmitAvailabilityWarning(Sema::AD_Deprecation, @@ -11859,8 +11859,11 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, } else if (CXXDestructorDecl *Destructor = dyn_cast(Func)) { Destructor = cast(Destructor->getFirstDecl()); - if (Destructor->isDefaulted() && !Destructor->isDeleted()) + if (Destructor->isDefaulted() && !Destructor->isDeleted()) { + if (Destructor->isTrivial() && !Destructor->hasAttr()) + return; DefineImplicitDestructor(Loc, Destructor); + } if (Destructor->isVirtual() && getLangOpts().AppleKext) MarkVTableUsed(Loc, Destructor->getParent()); } else if (CXXMethodDecl *MethodDecl = dyn_cast(Func)) { diff --git a/test/CodeGenCXX/trivial-constructor-init.cpp b/test/CodeGenCXX/trivial-constructor-init.cpp index 9130e4e5d9..da17799dfa 100644 --- a/test/CodeGenCXX/trivial-constructor-init.cpp +++ b/test/CodeGenCXX/trivial-constructor-init.cpp @@ -32,3 +32,17 @@ static C c[4]; int main() { } + +namespace PR22793 { +template +struct foo { +protected: +// CHECK-NOT: _ZN7PR227933fooIiED2Ev + ~foo() = default; + friend void func(); +}; + +void func() { foo f; } + +template struct foo; +}