@@ -71,8 +71,8 @@ For example:
71
71
.. code-block :: c++
72
72
73
73
void f(Foo foo) {
74
- if (foo.opt ().has_value()) {
75
- use(*foo.opt ()); // unsafe: it is unclear whether `foo.opt ()` has a value.
74
+ if (foo.take ().has_value()) {
75
+ use(*foo.take ()); // unsafe: it is unclear whether `foo.take ()` has a value.
76
76
}
77
77
}
78
78
@@ -81,10 +81,11 @@ Exception: accessor methods
81
81
82
82
The check assumes *accessor * methods of a class are stable, with a heuristic to
83
83
determine which methods are accessors. Specifically, parameter-free ``const ``
84
- methods are treated as accessors. Note that this is not guaranteed to be safe
85
- -- but, it is widely used (safely) in practice, and so we have chosen to treat
86
- it as generally safe. Calls to non ``const `` methods are assumed to modify
87
- the state of the object and affect the stability of earlier accessor calls.
84
+ methods and smart pointer-like APIs (non ``const `` overloads of ``* `` when
85
+ there is a parallel ``const `` overload) are treated as accessors. Note that
86
+ this is not guaranteed to be safe -- but, it is widely used (safely) in
87
+ practice. Calls to non ``const `` methods are assumed to modify the state of
88
+ the object and affect the stability of earlier accessor calls.
88
89
89
90
Rely on invariants of uncommon APIs
90
91
-----------------------------------
@@ -191,14 +192,15 @@ paths that lead to an access. For example:
191
192
Stabilize function results
192
193
~~~~~~~~~~~~~~~~~~~~~~~~~~
193
194
194
- Since function results are not assumed to be stable across calls, it is best to
195
- store the result of the function call in a local variable and use that variable
196
- to access the value. For example:
195
+ Function results are not assumed to be stable across calls, except for
196
+ const accessor methods. For more complex accessors (non-const, or depend on
197
+ multiple params) it is best to store the result of the function call in a
198
+ local variable and use that variable to access the value. For example:
197
199
198
200
.. code-block :: c++
199
201
200
202
void f(Foo foo) {
201
- if (const auto& foo_opt = foo.opt (); foo_opt.has_value()) {
203
+ if (const auto& foo_opt = foo.take (); foo_opt.has_value()) {
202
204
use(*foo_opt);
203
205
}
204
206
}
0 commit comments