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

Samuel Benzaquen via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 4 08:51:26 PDT 2016


sbenza added a comment.

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

> At least in my codebase, skipping templates is too strong. I run across ones where the const& parameter is not one controlled by a template. It's often a size_t.


The only check we are doing (other than matching type) is matching spelling.
This means that it will only skip templates where that type is spelled, for example, using the template argument.

So it will skip this `template <typename T> void Foo(const T&);` but not this `template <typename T> void Foo(const T&, const size_t&);` (for the `size_t` argument).
It will also skip things like `void Foo(const T&, const typename T::difference_type&);`

The idea is that if the spelling is not exact, then there is some external factor that can change what the type means and make the by-value option less efficient.

> I could easily see not fixing the typedef'd refs, also, although I think warning on them is still useful. Particularly if they can then be added to a list to be changed. E.g. size_t.


Warning on types that will never be added to the list and that should be taken by `const&` will lead to constant false positives.
We could make these warnings opt-in. This way some users might turn it on always or just turn it on to find the list of types.


http://reviews.llvm.org/D18191





More information about the cfe-commits mailing list