R# suggests const for arguments passed by value

While it is very useful to have const suggestions for pointer and reference arguments, I don't think it makes as much sense for arguments that are passed by value:

I am aware that there exist arguments for using const for pass-by-value arguments. However, the C++ Core Guidelines don't say arguments passed by value should be const:   http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rconst-ref.

So personally I don't think that const by value arguments should be suggested by default.

 

At least this option

Should be split into two options: one option for arguments that are passed by value and an other option for passed by pointer and/or reference.

5 comments

Hello,

"Parameter may be const" is already turned off for pointers and references. We'll consider changing its default severity and/or adding more options that allow to control its behaviour.

Thanks for the feedback!

0

That's exactly the other way around as it should be :)

 

For pointers and references it should be ON by default, since it is useful to const a reference or pointer argument when possible.

For pass-by-value it should be OFF by default.

 

 

0

It might be useful to convert a pointer to an object to a pointer to a constant object, not to a const pointer to an object. ReSharper does not yet have an inspection for the former (the request is https://youtrack.jetbrains.com/issue/RSCPP-20200), but clang-tidy does (https://clang.llvm.org/extra/clang-tidy/checks/readability-non-const-parameter.html), and R++ will show inspections from clang-tidy starting with 2017.3.

0

Thank you for the information - I didn't knew that there already exists an issue to separate the option into two. Looking forward to 2017.3 then.

Regarding clang-tidy inspections: does that mean that R++ will stop suggesting const for pass-by-value, like clang-tidy does? (Example 3). Asking because that was exactly the point of my initial post.

0

clang-tidy is support is already available in EAP builds (https://www.jetbrains.com/resharper/eap/). The existing ReSharper inspections will remain and will work alongside clang-tidy. As I've said, we'll consider changing the default severity of "Parameter may be const", you can just turn it off for now.

0

Please sign in to leave a comment.