I know there are a bunch of static analysis tools available for c++. However when googling I could not find one that seems to be able to warn about values and functions that could have been marked as const but aren't.
So in particular if I have a function like this:
int add(int a, const int b) {
int result = a + b;
return result;
}
I want the tool to warn me (or issue an error) about the variables a and result which could have been marked as const but weren't.
Furthermore if add had been a member function I would also want to be warned about it not being declared as `const.
So for one I want a tool that helps me enforcing const-correctness and if possible it should go beyond that and should make me use const in every single situation that my code currently allows for.
Are there tools that can do this for c++? Or is this even a compiler option in e.g. clang that I can't seem to find?
I was thinking that maybe this would be something that could be done with clang-tidy somehow if there is not a tool available already...
Resharper-C++ for VisualStudio does warn about that (it's not free). I am not sure what they use behind the scenes. It could just be clang-tidy.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With