This is an archive of the discontinued LLVM Phabricator instance.

[NFC][Clang] Fix static analyzer tool remark about missing user-defined assignment operator
ClosedPublic

Authored by Manna on Apr 12 2023, 7:22 PM.

Details

Summary

Reported by Coverity:

Copy without assign
This class has a user-defined copy constructor but no user-defined assignment operator. If the copy constructor is necessary to manage owned resources then a corresponding assignment operator is usually required. If an object of this type is assigned memory leaks and/or use-after-free errors may occur. Note that a compiler-generated assignment operator will perform only a bit-wise copy for any fields that do not have their own assignment operators defined.

Class has user-written copy constructor but no user-written assignment operator

copy_without_assign: Class <unnamed>::DeclUseTracker has a user-written copy constructor <unnamed>::DeclUseTracker::DeclUseTracker(<unnamed>::DeclUseTracker const &) =delete but no corresponding user-written assignment operator.

Diff Detail

Event Timeline

Manna created this revision.Apr 12 2023, 7:22 PM
Herald added a project: Restricted Project. · View Herald Transcript
Manna requested review of this revision.Apr 12 2023, 7:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2023, 7:22 PM
aaron.ballman accepted this revision.Apr 13 2023, 5:36 AM

LGTM! It's not strictly needed (the move constructor causes the implicit assignment operator to be deleted: https://eel.is/c++draft/class.copy.assign#2.sentence-2), but I think it's more clear to be explicit.

This revision is now accepted and ready to land.Apr 13 2023, 5:36 AM

Thank you @aaron.ballman for reviews and feedback.

The lit test failure seem unrelated to my fix:
https://buildkite.com/llvm-project/premerge-checks/builds/146438#0187786e-2f04-40a2-acf1-78eee9f00e7f

Failed Tests (1):

Clang :: SemaCXX/warn-unsafe-buffer-usage-fixits-pre-increment.cpp
This revision was landed with ongoing or failed builds.Apr 17 2023, 7:25 PM
This revision was automatically updated to reflect the committed changes.