[PATCH] D70390: [clang-tidy] new performance-no-automatic-move check.

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 19 07:26:57 PST 2019


Quuxplusone added a comment.

Hi, I'm the main original author (although I would not claim "current maintainer") of the Clang warning.
Clang doesn't warn about `const vector<int> v; return v;` because in that case, adding `std::move` to the return would not help anything. I had not considered that we might suggest a "fixit" of "Change the declared type of this variable from `vector` to `const vector`"; that sounds like a big non-local change whose correctness would be very difficult to verify. I think (FWIW) that such a fixit would be a very hard sell, but at the same time I admit that I had not even thought of it when I was working on the diagnostic originally.

If you're working in this area, I would also caution you that C++2a is going to completely rewrite the rules in this area. In C++2a, everything that Clang currently warns about is going to be //fixed in the standard//, so that the Clang warning becomes merely part of `-Wc++17-compat`. Nobody is currently working on that Clang patch AFAIK. If you're interested in submitting Clang patches in this area, that might be a very high-value (if kind of fuzzy/user-experience/political) patch to work on!

Meanwhile, as of November 2019, the C++2a committee draft still contains unfixed corner cases that Clang doesn't warn about. For example:
https://godbolt.org/z/fBKM-4 (no warning from Clang; C++2a fixes this behavior)
https://godbolt.org/z/EfBCdQ (no warning from Clang; C++2a does NOT fix this behavior)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70390/new/

https://reviews.llvm.org/D70390





More information about the cfe-commits mailing list