Skip to content

Commit c589057

Browse files
committed
Add code examples in the documentation
1 parent c6bc9c5 commit c589057

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,45 @@ The goal of this rule is to make sure that any NS or CF local variable is backed
36743674
36753675
The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
36763676
3677+
These are examples of cases that we consider safe:
3678+
3679+
.. code-block:: cpp
3680+
3681+
void foo1() {
3682+
RetainPtr<NSObject> retained;
3683+
// The scope of unretained is EMBEDDED in the scope of retained.
3684+
{
3685+
NSObject* unretained = retained.get(); // ok
3686+
}
3687+
}
3688+
3689+
void foo2(RetainPtr<NSObject> retained_param) {
3690+
NSObject* unretained = retained_param.get(); // ok
3691+
}
3692+
3693+
void FooClass::foo_method() {
3694+
NSObject* unretained = this; // ok
3695+
}
3696+
3697+
Here are some examples of situations that we warn about as they *might* be potentially unsafe. The logic is that either we're able to guarantee that a local variable is safe or it's considered unsafe.
3698+
3699+
.. code-block:: cpp
3700+
3701+
void foo1() {
3702+
NSObject* unretained = [[NSObject alloc] init]; // warn
3703+
}
3704+
3705+
NSObject* global_unretained;
3706+
void foo2() {
3707+
NSObject* unretained = global_unretained; // warn
3708+
}
3709+
3710+
void foo3() {
3711+
RetainPtr<NSObject> retained;
3712+
// The scope of unretained is not EMBEDDED in the scope of retained.
3713+
NSObject* unretained = retained.get(); // warn
3714+
}
3715+
36773716
Debug Checkers
36783717
---------------
36793718

0 commit comments

Comments
 (0)