[PATCH] D69145: Give readability-redundant-member-init an option IgnoreBaseInCopyConstructors to avoid breaking code with gcc -Werror=extra

Conrad Poelman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 8 17:54:01 PST 2019


poelmanc added a comment.

In D69145#1725026 <https://reviews.llvm.org/D69145#1725026>, @malcolm.parsons wrote:

> I like that this check warns about copy constructors that don't copy.
>  The warning can be suppressed with a NOLINT comment if not copying is intentional.


Thanks for the comment! It's not clear to me how you suggest proceeding though.

I think it would be great to have a warning about "copy constructors that don't copy", which I would expect to warn regardless of whether the default initialization is explicit, e.g.

  MyClass( const MyClass& other) : BaseClass() {...}`

or implicit, e.g.

  MyClass( const MyClass& other) {...}

An intelligent "copy constructors that don't copy" warning might even examine the `{...}` to see what's being handled there.

Unfortunately currently we have two tools each of which warns in one case but not the other:

- `gcc -Wextra` warns only in the latter case, and can be fixed by changing each occurrence to the former.
- clang-tidy's current `readability-redundant-member-init` check warns only in the former case, and fixes it by changing each occurrence to the latter.
  - (Also clang-tidy's warning about `: BaseClass()` being redundant isn't a very clear warning about copy constructor that don't copy.)

This patch just offers an option to make peace between the two tools.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69145/new/

https://reviews.llvm.org/D69145





More information about the cfe-commits mailing list