This is an archive of the discontinued LLVM Phabricator instance.

Add clang-tidy check for missing move constructors
Needs ReviewPublic

Authored by mbid on Nov 15 2022, 6:46 AM.

Diff Detail

Event Timeline

mbid created this revision.Nov 15 2022, 6:46 AM
Herald added a project: Restricted Project. · View Herald Transcript
mbid requested review of this revision.Nov 15 2022, 6:46 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 15 2022, 6:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
mbid added inline comments.Nov 15 2022, 6:55 AM
clang/include/clang/Lex/Token.h
101

This change is necessary to make isOneOf work with a single argument (and also no arguments). isOneOf is called from findNextAnyTokenKind, which is used in this patch with a single token type.

Eugene.Zelenko added inline comments.
clang-tools-extra/docs/clang-tidy/checks/performance/missing-move-constructor.rst
6

Please synchronize this sentence with Release Notes.

Eugene.Zelenko removed a project: Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 7:26 AM

What is the purpose of this check when we have cppcoreguidelines-special-member-functions.
Granted that check won't emit replacements, however the replacements that this check generates would often not improve performance or potentially introduce a bug.

I know its not nearly the same, but clangd can also fix this interactively with its special members refactor

mbid added a comment.Nov 17 2022, 1:40 PM

Hi Nathan, thanks for looking into this. I did indeed not know about the existing check in cppcoreguidelines -- maybe I should've been more suspicious about assuming something so obvious supposedly doesn't exist yet :)

But perhaps the replacements could still be integrated into the existing check. Note that replacements in my patch are generated only if you have a defaulted copying version. So e.g. the defaulted move constructor is emitted only if the class has a default copy constructor. This can still introduce bugs, but I think the probability for that is fairly low.

For context, I'm trying to run this on the chromium codebase, where copy constructors are required to be defined (even if = default) in the .cpp file for all non-trivial classes, which is why the implicit move constructors are often missing. I want to understand what the performance impact of that is.

the replacements that this check generates would often not improve performance

Why would you expect there to be no improvement? If there's a default copy constructor and hence no (implicit) move constructor, than the more expensive copying version will be invoked when a move would be sufficient.

LegalizeAdulthood resigned from this revision.Mar 29 2023, 8:08 AM