This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] ignore NRVO const variables in performance-no-automatic-move.
ClosedPublic

Authored by gnanabit on Apr 2 2023, 2:39 PM.

Details

Summary

In the following code:

cc
struct Obj {
  Obj();
  Obj(const Obj &);
  Obj(Obj &&);
  virtual ~Obj();
};

Obj ConstNrvo() {
  const Obj obj;
  return obj;
}

performance-no-automatic-move warns about the constness of obj. However, NRVO
is applied to obj, so the const should have no effect on performance.

This change modifies the matcher to exclude NRVO variables.

#clang-tidy

Diff Detail

Event Timeline

gnanabit created this revision.Apr 2 2023, 2:39 PM
Herald added a project: Restricted Project. · View Herald Transcript
gnanabit requested review of this revision.Apr 2 2023, 2:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2023, 2:39 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gnanabit updated this revision to Diff 510374.Apr 2 2023, 2:45 PM

Fix typo in CHECK-MESSAGES (should warn about obj2, not obj1).

courbet accepted this revision.Apr 2 2023, 11:09 PM

Thanks for the patch.

This revision is now accepted and ready to land.Apr 2 2023, 11:09 PM
PiotrZSL accepted this revision.Apr 3 2023, 8:18 AM

Current change is correct.
This check could be improved in future.
LGTM.

Add release notes entry !.

gnanabit updated this revision to Diff 510532.Apr 3 2023, 9:17 AM

Add release notes entry.

Thanks for the reviews! Happy to reword the release notes if they are unclear.

@courbet or @PiotrZSL, I don't have commit access. Can you land this patch for
me? Please use "Logan Gnanapragasam (gnanabit@google.com)" to commit the change.