[PATCH] Warn on explicit copy constructors.
Arthur O'Dwyer
arthur.j.odwyer at gmail.com
Tue Apr 29 08:28:29 PDT 2014
On Tue, Apr 29, 2014 at 6:58 AM, Alexander Kornienko <alexfh at google.com> wrote:
>
> http://reviews.llvm.org/D3541
> + if (Ctor->isOutOfLine() || Ctor->isImplicit() || Ctor->isDeleted())
> return;
> + if (Ctor->isExplicit() || Ctor->isCopyOrMoveConstructor()) {
> + if (Ctor->isExplicit() && Ctor->isCopyOrMoveConstructor()) {
> + SourceRange ExplicitTokenRange = FindToken(
> + *Result.SourceManager, Result.Context->getLangOpts(),
> + Ctor->getOuterLocStart(), Ctor->getLocEnd(), [](const Token &Tok) {
> + return Tok.is(tok::raw_identifier) &&
> + StringRef(Tok.getRawIdentifierData(), Tok.getLength()) ==
> + "explicit";
> + });
> + if (ExplicitTokenRange.isValid()) {
> + DiagnosticBuilder Diag =
> + diag(ExplicitTokenRange.getBegin(),
> + "Copy constructor declared explicit.");
You mean "copy or move constructor"; and you could use a test for the
move-constructor case.
There are corner cases such as
C(const C&&);
C(const C&, int i = 0);
template<typename T> C(const T&);
that would be interesting to test.
–Arthur
More information about the cfe-commits
mailing list