DeclaredCopyConstructor bits in CXXRecordDecl's DefinitionData
structure. Rather than having Sema call addedConstructor or set the
bits directly at semi-random places, move all of the logic for
managing these bits into CXXRecordDecl itself and tie the
addedConstructor call into DeclContext::addDecl().
This makes it easier for AST-building clients to get the right bits
set in DefinitionData, and is one small part of <rdar://problem/
8459981>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114889
91177308-0d34-0410-b5e6-
96231b3b80d8
void CheckConversionFunction(NamedDecl *D);
#endif
+ friend class DeclContext;
+
+ /// \brief Notify the class that another constructor has
+ /// been added.
+ ///
+ /// This routine helps maintain information about the class based on which
+ /// constructors have been added. It will be invoked by DeclContext::addDecl()
+ /// whenever a constructor is added to this record.
+ void addedConstructor(CXXConstructorDecl *ConDecl);
+
protected:
CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
return data().DeclaredDefaultConstructor;
}
- /// \brief Note whether this class has already had its default constructor
- /// implicitly declared or doesn't need one.
- void setDeclaredDefaultConstructor(bool DDC) {
- data().DeclaredDefaultConstructor = DDC;
- }
-
/// hasConstCopyConstructor - Determines whether this class has a
/// copy constructor that accepts a const-qualified argument.
bool hasConstCopyConstructor(ASTContext &Context) const;
/// a unique copy-assignment operator could not be found.
CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const;
- /// addedConstructor - Notify the class that another constructor has
- /// been added. This routine helps maintain information about the
- /// class based on which constructors have been added.
- void addedConstructor(ASTContext &Context, CXXConstructorDecl *ConDecl);
-
/// hasUserDeclaredConstructor - Whether this class has any
/// user-declared constructors. When true, a default constructor
/// will not be implicitly declared.
return data().DeclaredCopyConstructor;
}
- /// \brief Note whether this class has already had its copy constructor
- /// declared.
- void setDeclaredCopyConstructor(bool DCC) {
- data().DeclaredCopyConstructor = DCC;
- }
-
/// addedAssignmentOperator - Notify the class that another assignment
/// operator has been added. This routine helps maintain information about the
/// class based on which operators have been added.
} else {
FirstDecl = LastDecl = D;
}
+
+ if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(this)) {
+ Decl *InnerD = D;
+ if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
+ InnerD = FunTmpl->getTemplatedDecl();
+ if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(InnerD))
+ Record->addedConstructor(Constructor);
+ }
}
void DeclContext::addDecl(Decl *D) {
}
void
-CXXRecordDecl::addedConstructor(ASTContext &Context,
- CXXConstructorDecl *ConDecl) {
- assert(!ConDecl->isImplicit() && "addedConstructor - not for implicit decl");
+CXXRecordDecl::addedConstructor(CXXConstructorDecl *Constructor) {
+ // Ignore friends.
+ if (Constructor->getFriendObjectKind())
+ return;
+
+ if (Constructor->isImplicit()) {
+ // If this is the implicit default constructor, note that we have now
+ // declared it.
+ if (Constructor->isDefaultConstructor())
+ data().DeclaredDefaultConstructor = true;
+ // If this is the implicit copy constructor, note that we have now
+ // declared it.
+ else if (Constructor->isCopyConstructor())
+ data().DeclaredCopyConstructor = true;
+
+ // Nothing else to do for implicitly-declared constructors.
+ return;
+ }
+
// Note that we have a user-declared constructor.
data().UserDeclaredConstructor = true;
// Note when we have a user-declared copy constructor, which will
// suppress the implicit declaration of a copy constructor.
- if (ConDecl->isCopyConstructor()) {
+ if (!Constructor->getDescribedFunctionTemplate() &&
+ Constructor->isCopyConstructor()) {
data().UserDeclaredCopyConstructor = true;
data().DeclaredCopyConstructor = true;
// A copy constructor is trivial if it is implicitly declared.
// FIXME: C++0x: don't do this for "= default" copy constructors.
data().HasTrivialCopyConstructor = false;
-
}
}
Constructor->setInvalidDecl();
}
}
-
- // Notify the class that we've added a constructor. In principle we
- // don't need to do this for out-of-line declarations; in practice
- // we only instantiate the most recent declaration of a method, so
- // we have to call this for everything but friends.
- if (!Constructor->getFriendObjectKind())
- ClassDecl->addedConstructor(Context, Constructor);
}
/// CheckDestructor - Checks a fully-formed destructor definition for
DefaultCon->setTrivial(ClassDecl->hasTrivialConstructor());
// Note that we have declared this constructor.
- ClassDecl->setDeclaredDefaultConstructor(true);
++ASTContext::NumImplicitDefaultConstructorsDeclared;
if (Scope *S = getScopeForContext(ClassDecl))
CopyConstructor->setTrivial(ClassDecl->hasTrivialCopyConstructor());
// Note that we have declared this constructor.
- ClassDecl->setDeclaredCopyConstructor(true);
++ASTContext::NumImplicitCopyConstructorsDeclared;
// Add the parameter to the constructor.