From 7d125a11f152e1907b4eb50e48430cd89c0f130e Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 27 Nov 2012 21:20:31 +0000 Subject: [PATCH] Simplify checking for whether we should implicitly declare special members and add some assertions. No functionality change. llvm-svn: 168725 --- clang/lib/Sema/SemaDeclCXX.cpp | 5 ++++- clang/lib/Sema/SemaLookup.cpp | 25 +++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index e98f75ebe6d7..e950f3eb0984 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -6991,7 +6991,7 @@ CXXConstructorDecl *Sema::DeclareImplicitDefaultConstructor( // user-declared constructor for class X, a default constructor is // implicitly declared. An implicitly-declared default constructor // is an inline public member of its class. - assert(!ClassDecl->hasUserDeclaredConstructor() && + assert(ClassDecl->needsImplicitDefaultConstructor() && "Should not build implicit default constructor!"); bool Constexpr = defaultedSpecialMemberIsConstexpr(*this, ClassDecl, @@ -7304,6 +7304,7 @@ CXXDestructorDecl *Sema::DeclareImplicitDestructor(CXXRecordDecl *ClassDecl) { // If a class has no user-declared destructor, a destructor is // declared implicitly. An implicitly-declared destructor is an // inline public member of its class. + assert(!ClassDecl->hasDeclaredDestructor()); // Create the actual destructor declaration. CanQualType ClassType @@ -7856,6 +7857,7 @@ CXXMethodDecl *Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) { // constructor rules. Note that virtual bases are not taken into account // for determining the argument type of the operator. Note also that // operators taking an object instead of a reference are allowed. + assert(!ClassDecl->hasDeclaredCopyAssignment()); QualType ArgType = Context.getTypeDeclType(ClassDecl); QualType RetType = Context.getLValueReferenceType(ArgType); @@ -8695,6 +8697,7 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor( // C++ [class.copy]p4: // If the class definition does not explicitly declare a copy // constructor, one is declared implicitly. + assert(!ClassDecl->hasDeclaredCopyConstructor()); QualType ClassType = Context.getTypeDeclType(ClassDecl); QualType ArgType = ClassType; diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index f257a499d4ce..003c525e9f46 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -528,22 +528,17 @@ static bool LookupBuiltin(Sema &S, LookupResult &R) { /// \brief Determine whether we can declare a special member function within /// the class at this point. -static bool CanDeclareSpecialMemberFunction(ASTContext &Context, - const CXXRecordDecl *Class) { +static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class) { // We need to have a definition for the class. if (!Class->getDefinition() || Class->isDependentContext()) return false; // We can't be in the middle of defining the class. - if (const RecordType *RecordTy - = Context.getTypeDeclType(Class)->getAs()) - return !RecordTy->isBeingDefined(); - - return false; + return !Class->isBeingDefined(); } void Sema::ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class) { - if (!CanDeclareSpecialMemberFunction(Context, Class)) + if (!CanDeclareSpecialMemberFunction(Class)) return; // If the default constructor has not yet been declared, do so now. @@ -602,8 +597,7 @@ static void DeclareImplicitMemberFunctionsWithName(Sema &S, switch (Name.getNameKind()) { case DeclarationName::CXXConstructorName: if (const CXXRecordDecl *Record = dyn_cast(DC)) - if (Record->getDefinition() && - CanDeclareSpecialMemberFunction(S.Context, Record)) { + if (Record->getDefinition() && CanDeclareSpecialMemberFunction(Record)) { CXXRecordDecl *Class = const_cast(Record); if (Record->needsImplicitDefaultConstructor()) S.DeclareImplicitDefaultConstructor(Class); @@ -618,7 +612,7 @@ static void DeclareImplicitMemberFunctionsWithName(Sema &S, case DeclarationName::CXXDestructorName: if (const CXXRecordDecl *Record = dyn_cast(DC)) if (Record->getDefinition() && !Record->hasDeclaredDestructor() && - CanDeclareSpecialMemberFunction(S.Context, Record)) + CanDeclareSpecialMemberFunction(Record)) S.DeclareImplicitDestructor(const_cast(Record)); break; @@ -627,8 +621,7 @@ static void DeclareImplicitMemberFunctionsWithName(Sema &S, break; if (const CXXRecordDecl *Record = dyn_cast(DC)) { - if (Record->getDefinition() && - CanDeclareSpecialMemberFunction(S.Context, Record)) { + if (Record->getDefinition() && CanDeclareSpecialMemberFunction(Record)) { CXXRecordDecl *Class = const_cast(Record); if (!Record->hasDeclaredCopyAssignment()) S.DeclareImplicitCopyAssignment(Class); @@ -2233,9 +2226,9 @@ Sema::SpecialMemberOverloadResult *Sema::LookupSpecialMember(CXXRecordDecl *RD, bool RValueThis, bool ConstThis, bool VolatileThis) { - RD = RD->getDefinition(); - assert((RD && !RD->isBeingDefined()) && + assert(CanDeclareSpecialMemberFunction(RD) && "doing special member lookup into record that isn't fully complete"); + RD = RD->getDefinition(); if (RValueThis || ConstThis || VolatileThis) assert((SM == CXXCopyAssignment || SM == CXXMoveAssignment) && "constructors and destructors always have unqualified lvalue this"); @@ -2451,7 +2444,7 @@ CXXConstructorDecl *Sema::LookupMovingConstructor(CXXRecordDecl *Class, /// \brief Look up the constructors for the given class. DeclContext::lookup_result Sema::LookupConstructors(CXXRecordDecl *Class) { // If the implicit constructors have not yet been declared, do so now. - if (CanDeclareSpecialMemberFunction(Context, Class)) { + if (CanDeclareSpecialMemberFunction(Class)) { if (Class->needsImplicitDefaultConstructor()) DeclareImplicitDefaultConstructor(Class); if (!Class->hasDeclaredCopyConstructor())