40 lines · plain
1.. title:: clang-tidy - objc-nsinvocation-argument-lifetime2 3objc-nsinvocation-argument-lifetime4===================================5 6Finds calls to ``NSInvocation`` methods under ARC that don't have proper7argument object lifetimes. When passing Objective-C objects as parameters8to the ``NSInvocation`` methods ``getArgument:atIndex:`` and9``getReturnValue:``, the values are copied by value into the argument pointer,10which leads to incorrect releasing behavior if the object pointers are11not declared ``__unsafe_unretained``.12 13For code:14 15.. code-block:: objc16 17 id arg;18 [invocation getArgument:&arg atIndex:2];19 20 __strong id returnValue;21 [invocation getReturnValue:&returnValue];22 23The fix will be:24 25.. code-block:: objc26 27 __unsafe_unretained id arg;28 [invocation getArgument:&arg atIndex:2];29 30 __unsafe_unretained id returnValue;31 [invocation getReturnValue:&returnValue];32 33The check will warn on being passed instance variable references that have34lifetimes other than ``__unsafe_unretained``, but does not propose a fix:35 36.. code-block:: objc37 38 // "id _returnValue" is declaration of instance variable of class.39 [invocation getReturnValue:&self->_returnValue];40