Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using C-style casts in new code #3010

Open
daljit46 opened this issue Sep 19, 2024 · 2 comments
Open

Stop using C-style casts in new code #3010

daljit46 opened this issue Sep 19, 2024 · 2 comments

Comments

@daljit46
Copy link
Member

daljit46 commented Sep 19, 2024

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:

  • they're checked at compile time by the compiler (when it's possible to do so).
  • they express intent much better than C-style casts.
  • they're greppable (very useful when refactoring something).
@Lestropie
Copy link
Member

👍 Does clang-tidy catch these / can it autofix?

@daljit46
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants