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

Steve Downey via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 17 15:46:20 PDT 2016


sdowney added a comment.

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?


http://reviews.llvm.org/D18191





More information about the cfe-commits mailing list