From 86d17d3f763a8e6b2fad2711852ff63744487655 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 27 Mar 2011 21:26:48 +0000 Subject: [PATCH] Reduce indentation using early exits and add a couple of comments. No functionality changed. llvm-svn: 128396 --- clang/lib/Sema/SemaDeclCXX.cpp | 35 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 07d60caf435a..ee7e447641c2 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -6091,24 +6091,29 @@ bool Sema::InitializeVarWithConstructor(VarDecl *VD, } void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) { + if (VD->isInvalidDecl()) return; + CXXRecordDecl *ClassDecl = cast(Record->getDecl()); - if (!ClassDecl->isInvalidDecl() && !VD->isInvalidDecl() && - !ClassDecl->hasTrivialDestructor() && !ClassDecl->isDependentContext()) { - CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl); - MarkDeclarationReferenced(VD->getLocation(), Destructor); - CheckDestructorAccess(VD->getLocation(), Destructor, - PDiag(diag::err_access_dtor_var) - << VD->getDeclName() - << VD->getType()); + if (ClassDecl->isInvalidDecl()) return; + if (ClassDecl->hasTrivialDestructor()) return; + if (ClassDecl->isDependentContext()) return; - if (!VD->isInvalidDecl() && VD->hasGlobalStorage()) { - // TODO: this should be re-enabled for static locals by !CXAAtExit - if (!VD->isStaticLocal()) - Diag(VD->getLocation(), diag::warn_global_destructor); + CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl); + MarkDeclarationReferenced(VD->getLocation(), Destructor); + CheckDestructorAccess(VD->getLocation(), Destructor, + PDiag(diag::err_access_dtor_var) + << VD->getDeclName() + << VD->getType()); - Diag(VD->getLocation(), diag::warn_exit_time_destructor); - } - } + if (!VD->hasGlobalStorage()) return; + + // Emit warning for non-trivial dtor in global scope (a real global, + // class-static, function-static). + Diag(VD->getLocation(), diag::warn_exit_time_destructor); + + // TODO: this should be re-enabled for static locals by !CXAAtExit + if (!VD->isStaticLocal()) + Diag(VD->getLocation(), diag::warn_global_destructor); } /// AddCXXDirectInitializerToDecl - This action is called immediately after