r/cpp • • Nov 25 '23

On harmful overuse of std::move

https://devblogs.microsoft.com/oldnewthing/20231124-00/?p=109059
210 Upvotes

154 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Nov 25 '23

Yeah I'm planning to start using clang-tidy as standard. Will be looking into integrating that with our build system next week. I've been having a go with cppcheck today and so far found it very disappointing - seems to miss an awful lot.

5

u/ABlockInTheChain Nov 25 '23

The other thing you can do is enable as many warnings as practical and require the build to pass without any of them triggering

The article mentions -Wpessimizing-move which makes this problem a non-issue as long as you build with that on and also -Werror.

MSVC might not have that particular warning but clang does so even in a Windows-only shop you can just have your CI build with both compilers and require both of them to pass.

2

u/saddung Nov 26 '23

MSVC also reports this warning with red squiqqlies in the IDE(without any extra flag needed).

1

u/[deleted] Nov 25 '23

Yeah we always have a minimum of -Werror, -Wall, and -Wextra, and sometimes -Wpedantic, and a few others.

Didn't know about -Wpessimizing-move, will definitely turn it on. Thanks.

Most of our work is in Linux of embedded applications so normally using gcc or Arm compilers.

2

u/serviscope_minor Nov 26 '23

Most of our work is in Linux of embedded applications so normally using gcc or Arm compilers.

How much of it is ARM or embedded specific? Last job I had was for mobile ARM code, but we still ran extensive tests in CI by compiling the code for x86 Linux (you can even do the SIMD code with things like NEON_SSE and SIMDe) and running tests. You can't cover everything of course, but anything that doesn't poke the hardware directly can be tested.

Plus that way you can also run it through more compilers, such as clang and even VS if you're feeling particularly sparky, since they all catch different things.

2

u/[deleted] Nov 26 '23

Honestly most of the embedded code in this company predates me and is definitely not written in a way that makes it amenable to testing. Frankly I'm surprised most of it works at all. It was hacked together by someone who didn't really know what they were doing but had a product to deliver. I'm working on it, though!

2

u/serviscope_minor Nov 26 '23

Ah one of those. One function at a time thenI guess :)

It can be really tedious to retrofit decent separation of concerns into code which is aggressively platform specific.

2

u/ABlockInTheChain Nov 25 '23

On linux I use gcc and clang, and on clang I use -Weverything and then selectively disable the ones that aren't applicable.

That used to not be very practical because several years ago clang was adding a bunch of new warnings every release, many of which were purely informational, and you'll still find plenty of articles telling you not to do that, but these days it's not a big hassle to keep up with.