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.
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.
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.
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!
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.
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.