r208786 - Don't copy objects with trivial, deleted copy ctors
Reid Kleckner
rnk at google.com
Wed May 14 16:55:11 PDT 2014
On Wed, May 14, 2014 at 4:15 PM, Richard Smith <richard at metafoo.co.uk>wrote:
> > +bool CGCXXABI::canCopyArgument(const CXXRecordDecl *RD) const {
> > + // If RD has a non-trivial move or copy constructor, we cannot copy
> the
> > + // argument.
> > + if (RD->hasNonTrivialCopyConstructor() ||
> RD->hasNonTrivialMoveConstructor())
> > + return false;
> > +
> > + // If RD has a non-trivial destructor, we cannot copy the argument.
> > + if (RD->hasNonTrivialDestructor())
> > + return false;
> > +
> > + // We can only copy the argument if there exists at least one trivial,
> > + // non-deleted copy or move constructor.
> > + // FIXME: This assumes that all lazily declared copy and move
> constructors are
> > + // not deleted. This assumption might not be true in some corner
> cases.
> > + bool CopyOrMoveDeleted = false;
> > + for (const CXXConstructorDecl *CD : RD->ctors()) {
> > + if (CD->isCopyConstructor() || CD->isMoveConstructor()) {
> > + assert(CD->isTrivial());
> > + // We had at least one undeleted trivial copy or move ctor.
> Return
> > + // directly.
> > + if (!CD->isDeleted())
> > + return true;
> > + CopyOrMoveDeleted = true;
> > + }
> > + }
> > +
> > + // If all trivial copy and move constructors are deleted, we cannot
> copy the
> > + // argument.
> > + return !CopyOrMoveDeleted;
>
> This returns false if either trivial copy or move is deleted. Shouldn't we
> only return false if both of them are?
>
Is it possible to delete a copy or move constructor without forcing the
other constructors to be declared? They appear to go together. It's good
to be defensive though.
> > +}
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140514/9cedf97f/attachment.html>
More information about the cfe-commits
mailing list