1.. title:: clang-tidy - performance-unnecessary-value-param
2
3performance-unnecessary-value-param
4===================================
5
6Flags value parameter declarations of expensive to copy types that are copied
7for each invocation but it would suffice to pass them by const reference.
8
9The check is only applied to parameters of types that are expensive to copy
10which means they are not trivially copyable or have a non-trivial copy
11constructor or destructor.
12
13To ensure that it is safe to replace the value parameter with a const reference
14the following heuristic is employed:
15
161. the parameter is const qualified;
172. the parameter is not const, but only const methods or operators are invoked
18   on it, or it is used as const reference or value argument in constructors or
19   function calls.
20
21Example:
22
23.. code-block:: c++
24
25  void f(const string Value) {
26    // The warning will suggest making Value a reference.
27  }
28
29  void g(ExpensiveToCopy Value) {
30    // The warning will suggest making Value a const reference.
31    Value.ConstMethd();
32    ExpensiveToCopy Copy(Value);
33  }
34
35If the parameter is not const, only copied or assigned once and has a
36non-trivial move-constructor or move-assignment operator respectively the check
37will suggest to move it.
38
39Example:
40
41.. code-block:: c++
42
43  void setValue(string Value) {
44    Field = Value;
45  }
46
47Will become:
48
49.. code-block:: c++
50
51  #include <utility>
52
53  void setValue(string Value) {
54    Field = std::move(Value);
55  }
56
57Options
58-------
59
60.. option:: IncludeStyle
61
62   A string specifying which include-style is used, `llvm` or `google`. Default
63   is `llvm`.
64
65.. option:: AllowedTypes
66
67   A semicolon-separated list of names of types allowed to be passed by value.
68   Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches every type
69   with suffix `Ref`, `ref`, `Reference` and `reference`. The default is empty.
70