Skip to content

Objective-C++ implicit ivar access uses local self shadow rather than method's implicit self #56193

Open
@mwyman

Description

C++ skips the Objective-C name lookup behavior that filters non-implicit-self, and will instead find local variables that shadow self:

__attribute__((objc_root_class))
@interface TestClass
@end

extern TestClass *CreateObject(void) __attribute__((ns_returns_retained));

@implementation TestClass {
  int _value;
}

- (void)foo {
  _value = 0;
  {
    TestClass *self = CreateObject();
    _value = 42;  // In ObjC, this updates the method's self, in ObjC++ it modifies local shadow.
  }
}
@end

When this shadowing occurs in a block, in Objective-C++ the -Wimplicit-retain-self warning is still emitted on bare ivar access but the ivar updates the local ivar on the local self and does not trigger a strong retain of the implicit self from the method.

It appears that Sema::CppLookupName is missing a similar check for non-implicit-self names (e.g. here).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"objective-c

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions