This patch will:
- replace all occurrence of the C "memcpy" function by "std::copy".
- reorder its arguments.
- insert the "algorithm" header if needed.
Differential D63324
[clang-tidy] Replace memcpy by std::copy Blackhart on Jun 14 2019, 2:48 AM. Authored by
Details This patch will:
Diff Detail Event TimelineComment Actions According with the C++ reference, std::copy is only available since C++20. I'm working on the unit tests and I'll make documentation/releasenotes after that. Thanks for reviewing @lebedev.ri ;) Comment Actions I don't see it there, can you quote?
Comment Actions This might not be currently ideal recommendation since std::copy produces memmove with -O3. Comment Actions New check must be mentioned in Release Notes and its documentation provided.
Comment Actions Sorry, I misread the reference. It's "until" C++20. I'll revert my changes. Comment Actions What do you recommend ?
Comment Actions Hello, I've updated the documentation with more informations about the transformations the check do. I'm not very confident in writing documentation in english.
Comment Actions You need tests for this check. Please harden them against macro-interference as well. I think the transformation should happen as function call that return Optional and if any failure happens the diagnostic can still be emitted.
Comment Actions Thinking about it more, i have some negative reservations about this :/ As it can be seen form https://godbolt.org/z/3BZmCM, it seems any and every(?) alternative C++ algorithm Comment Actions if(num != 0) memmove is missed optimization opportunity. Such branch can be removed (if profitable).
|
In English, it's more idiomatic to say "Replace memcpy with std::copy",
but perhaps an even better name for this check is modernize-use-std-copy.
This opens the door to future improvements that recognize hand-written
for loops that are essentially just invocations of std::copy or std::copy_n.
(Recently I was considering writing a check like that while reviewing some
code at work that was full of hand-written for loops that just copied elements
from one container to another.)