This is an archive of the discontinued LLVM Phabricator instance.

[clang] 'unused-but-set-variable' warning should not apply to __block objective-c pointers

Authored by arphaman on Oct 29 2021, 3:15 PM.



The __block Objective-C pointers can be set but not used due to a commonly used lifetime extension pattern in Objective-C.

Diff Detail

Event Timeline

arphaman created this revision.Oct 29 2021, 3:15 PM
arphaman requested review of this revision.Oct 29 2021, 3:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2021, 3:15 PM

This seems reasonable to me, but I don't know Objective C. Presumably someone who does should accept.

This revision is now accepted and ready to land.Nov 4 2021, 11:44 AM

The lifetime of an object won't be extended in the following case since the variable isn't captured by a block:

void foo(id);

void test(id a) {
    __block id t = a;
    t = 0;

clang should probably warn if a variable marked __block isn't captured by a block, but I don't think -Wunused-but-set-variable should catch that.