Debian Codegraph @

llvm-project/clang-tools-extra/docs/clang-tidy/checks/bugprone/argument-comment.rst

raw
1 .. title:: clang-tidy - bugprone-argument-comment
2
3 bugprone-argument-comment
4 =========================
5
6 Checks that argument comments match parameter names.
7
8 The check understands argument comments in the form ``/*parameter_name=*/``
9 that are placed right before the argument.
10
11 .. code-block:: c++
12
13 void f(bool foo);
14
15 ...
16
17 f(/*bar=*/true);
18 // warning: argument name 'bar' in comment does not match parameter name 'foo'
19
20 The check tries to detect typos and suggest automated fixes for them.
21
22 Options
23 -------
24
25 .. option:: StrictMode
26
27 When `false` (default value), the check will ignore leading and trailing
28 underscores and case when comparing names -- otherwise they are taken into
29 account.
30
31 .. option:: IgnoreSingleArgument
32
33 When `true`, the check will ignore the single argument.
34
35 .. option:: CommentBoolLiterals
36
37 When `true`, the check will add argument comments in the format
38 ``/*ParameterName=*/`` right before the boolean literal argument.
39
40 Before:
41
42 .. code-block:: c++
43
44 void foo(bool TurnKey, bool PressButton);
45
46 foo(true, false);
47
48 After:
49
50 .. code-block:: c++
51
52 void foo(bool TurnKey, bool PressButton);
53
54 foo(/*TurnKey=*/true, /*PressButton=*/false);
55
56 .. option:: CommentIntegerLiterals
57
58 When true, the check will add argument comments in the format
59 ``/*ParameterName=*/`` right before the integer literal argument.
60
61 Before:
62
63 .. code-block:: c++
64
65 void foo(int MeaningOfLife);
66
67 foo(42);
68
69 After:
70
71 .. code-block:: c++
72
73 void foo(int MeaningOfLife);
74
75 foo(/*MeaningOfLife=*/42);
76
77 .. option:: CommentFloatLiterals
78
79 When true, the check will add argument comments in the format
80 ``/*ParameterName=*/`` right before the float/double literal argument.
81
82 Before:
83
84 .. code-block:: c++
85
86 void foo(float Pi);
87
88 foo(3.14159);
89
90 After:
91
92 .. code-block:: c++
93
94 void foo(float Pi);
95
96 foo(/*Pi=*/3.14159);
97
98 .. option:: CommentStringLiterals
99
100 When true, the check will add argument comments in the format
101 ``/*ParameterName=*/`` right before the string literal argument.
102
103 Before:
104
105 .. code-block:: c++
106
107 void foo(const char *String);
108 void foo(const wchar_t *WideString);
109
110 foo("Hello World");
111 foo(L"Hello World");
112
113 After:
114
115 .. code-block:: c++
116
117 void foo(const char *String);
118 void foo(const wchar_t *WideString);
119
120 foo(/*String=*/"Hello World");
121 foo(/*WideString=*/L"Hello World");
122
123 .. option:: CommentCharacterLiterals
124
125 When true, the check will add argument comments in the format
126 ``/*ParameterName=*/`` right before the character literal argument.
127
128 Before:
129
130 .. code-block:: c++
131
132 void foo(char *Character);
133
134 foo('A');
135
136 After:
137
138 .. code-block:: c++
139
140 void foo(char *Character);
141
142 foo(/*Character=*/'A');
143
144 .. option:: CommentUserDefinedLiterals
145
146 When true, the check will add argument comments in the format
147 ``/*ParameterName=*/`` right before the user defined literal argument.
148
149 Before:
150
151 .. code-block:: c++
152
153 void foo(double Distance);
154
155 double operator"" _km(long double);
156
157 foo(402.0_km);
158
159 After:
160
161 .. code-block:: c++
162
163 void foo(double Distance);
164
165 double operator"" _km(long double);
166
167 foo(/*Distance=*/402.0_km);
168
169 .. option:: CommentNullPtrs
170
171 When true, the check will add argument comments in the format
172 ``/*ParameterName=*/`` right before the nullptr literal argument.
173
174 Before:
175
176 .. code-block:: c++
177
178 void foo(A* Value);
179
180 foo(nullptr);
181
182 After:
183
184 .. code-block:: c++
185
186 void foo(A* Value);
187
188 foo(/*Value=*/nullptr);