[PATCH] D15332: new clang-tidy checker readability-non-const-parameter
Richard via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 17 08:33:52 PST 2016
LegalizeAdulthood added inline comments.
================
Comment at: test/clang-tidy/readability-non-const-parameter.cpp:3
@@ +2,3 @@
+
+// Currently the checker only warns about pointer arguments.
+//
----------------
danielmarjamaki wrote:
> LegalizeAdulthood wrote:
> > How hard is it to extend it to references?
> >
> > Certainly the confusion about what is const is easier to resolve in the case of references because the references themselves are immutable.
> If a "int &" reference parameter is not written then probably it's better to pass it by value than making it const. I would prefer that unless it has to use "int &" to comply with some interface.
>
> I realize that the same can be said about pointers. If there is a "int *p" and you just read the value that p points at .. maybe sometimes it would be preferable to pass it by value.
I thought the point of this check was to identify stuff passed by reference/pointer that could instead be passed by const reference/pointer.
Passing a read-only number type (`short`, `char`, `int`, `float`, `double`, etc.) parameter by pointer or by reference/pointer is a code smell, but this check isn't trying to identify that situation.
I'm more interested in things like:
```
void foo(std::string &s);
```
becoming
```
void foo(const std::string &s);
```
when `s` is treated as a read-only value within the implementation of `foo`.
http://reviews.llvm.org/D15332
More information about the cfe-commits
mailing list