This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available
ClosedPublic

Authored by AMS21 on Jun 18 2023, 12:41 AM.

Details

Summary

We now display a simple note if the reason is that the used class does not
support move semantics.

This fixes llvm#62550

Diff Detail

Event Timeline

AMS21 created this revision.Jun 18 2023, 12:41 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: xazax.hun. · View Herald Transcript
AMS21 requested review of this revision.Jun 18 2023, 12:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2023, 12:41 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
AMS21 added inline comments.Jun 18 2023, 12:43 AM
clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
345

I've tried to add

// CHECK-MESSAGES: [[@LINE+1]]:1: note: 'NonMoveConstructable' is not move constructible

here. But doing so actually fails the tests and I'm not quite sure why.

Overall looks ok,
Add some test with records being used via typedef.

clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
117

make sure you use here canonical type, or it may not work correctly with typedefs, like typedefs to records.
same in line 120, in fact only on line 154 would be good to use original type.

209

getLocation ()

211

<< RecordDecl
should work, do not use getName, it could cause crash for unnamed records.

clang-tools-extra/docs/ReleaseNotes.rst
378

"check to warn when ..."

clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
345

There are 2 ways to deal with this.
If you use CHECK-MESSAGES, then order of issues is checked, and that why for current notes you may see thing like @LINE-27, so you would need to put it into places when its emited.
Other way is to use CHECK-NOTES, then all warnings are checked out of order.
So simply I would put those CHECK-MESSAGES, after a warning in lines 256, 372, 384, 387

AMS21 updated this revision to Diff 532458.Jun 18 2023, 2:59 AM
AMS21 marked 5 inline comments as done.

Implement suggested changes
Add tests with typedefs

PiotrZSL accepted this revision.Jun 18 2023, 3:22 AM

+- LGTM

clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
210

You need t check RecordDecl here also.
like if (...; RecordDecl && !(RecordDecl->hasMoveConstructor() && RecordDecl->hasMoveAssignment()))

212

maybe this should be constructible/assignable depend on what we are missing (constructor, assign operator)...
Simply this may be strange to get warn about construct when we assign.
Still things like std::optional cold use move constructor instead of assign operator on assign.
So this wound need to be checked... It's fine if we won't be very detailed here

clang-tools-extra/docs/ReleaseNotes.rst
378

remove :

This revision is now accepted and ready to land.Jun 18 2023, 3:22 AM
AMS21 updated this revision to Diff 532466.Jun 18 2023, 4:15 AM
AMS21 marked 2 inline comments as done.

Implemented suggested changes

clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
345

Ah yes that makes total sense. Thanks for clarifying that :)

PiotrZSL accepted this revision.Jun 18 2023, 4:23 AM

LGTM

clang-tools-extra/docs/ReleaseNotes.rst
378–379
NOTE: check to warn when no move constructor is available. -> check to warn when move special member functions are not available. or something similar, to not limit this only to construction
AMS21 updated this revision to Diff 532467.Jun 18 2023, 4:31 AM

Improve doc

AMS21 added a comment.Jun 18 2023, 4:31 AM

As always if there are no more problems, I would kindly ask for someone to push this on my behalf :)

This revision was landed with ongoing or failed builds.Jun 18 2023, 4:42 AM
This revision was automatically updated to reflect the committed changes.