-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAV Rule 82.qhelp
More file actions
46 lines (36 loc) · 1.59 KB
/
AV Rule 82.qhelp
File metadata and controls
46 lines (36 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
This rule finds assignment operator definitions that do not return a reference to <code>this</code>.
The reference to <code>this</code> is required for an assignment expression to have a meaningful value
(i.e. so that expressions like <code>a = b = 3</code> would work correctly). Not returning a reference to
<code>this</code> would give the assignment expression an unexpected value, most likely causing such chained assignments to fail.
Both the standard library types and the built-in types behave in this manner, and the default behavior
of the assignment operator is an almost universal assumption of all developers that it is unwise to change
it considerably. If the desired behavior is significantly different from that of the default
assignment operator, it may be better to define a separate function instead.
</p>
</overview>
<recommendation>
<p>
Make sure that the assignment operator overload returns a reference to <code>this</code>. Define a separate
function if the desired assignment operator differs significantly from the default behavior.
</p>
</recommendation>
<example><sample src="AV Rule 82.cpp" />
</example>
<references>
<li>
AV Rule 82, <em>Joint Strike Fighter Air Vehicle C++ Coding Standards</em>. Lockheed Martin Corporation, 2005.
</li>
<li>
S. Meyers. <em>Effective C++ 3d ed.</em> pp 52-53. Addison-Wesley Professional, 2005.
</li>
<li>
<a href="http://courses.cms.caltech.edu/cs11/material/cpp/donnie/cpp-ops.html">C++ Operator Overloading Guidelines</a>
</li>
</references>
</qhelp>