MRtrix3 / mrtrix3

MRtrix3 provides a set of tools to perform various advanced diffusion MRI analyses, including constrained spherical deconvolution (CSD), probabilistic tractography, track-density imaging, and apparent fibre density
http://www.mrtrix.org
Mozilla Public License 2.0
292 stars 179 forks source link

Stop using C-style casts in new code #3010

Open daljit46 opened 1 week ago

daljit46 commented 1 week ago

There are several places in our codebase where we are relying on C-style casts instead of using C++ casts. While it's true that writing something like float(value) is shorter and arguably more readable than something like static_cast<float>(value), C-style casts are inherently a worse choice. In particular, there are three benefits of using C++ style casts:

Lestropie commented 1 week ago

:+1: Does clang-tidy catch these / can it autofix?

daljit46 commented 1 week ago

Clang-tidy does seem to have a check for this: cppcoreguidelines-pro-type-cstyle-cast, but in my experience it doesn't seem to provide a fixit (even though it should) and it also doesn't diagnose the issue properly in the majority of cases. Although, I probably should test this on various platforms to check whether it's an issue with my configuration.