[PATCH] D18191: [clang-tidy] Add check for function parameters that are const& to builtin types

Richard via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 18 14:21:07 PDT 2016


LegalizeAdulthood added a comment.

In http://reviews.llvm.org/D18191#377686, @sdowney wrote:

> In http://reviews.llvm.org/D18191#376471, @LegalizeAdulthood wrote:
>
> > There is utility in the definition of a function in saying that an argument is `const int i` instead of `int i`.  The const-ness declares the intent that this local variable is not going to be modified.  However, there is that oddity in C++ that allows a declaration to say `void f(int i);` and the implementation to say `void f(const int i) { ... }`.
> >
> > I think I would like the fixit to preserve the const-ness of the argument while still stripping it of it's reference.
>
>
> The usual pattern for that is to have the definition use const, and the declaration not, since it's an implementation detail if the passed parameter is modified. And, unfortunately, I'm stuck with one compiler that mangles those two differently, causing link errors.
>
> Having void foo(const int i) in a declaration makes me suspicious, since the const is meaningless.
>
> I could make this an option? If the option is set, emit 'const type' if the Decl hasBody?


It seems reasonable to do this as a refinement after this check is in place.


http://reviews.llvm.org/D18191





More information about the cfe-commits mailing list