Objective-C++ implicit ivar access uses local self shadow rather than method's implicit self #56193
Open
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.
}
}
@endWhen 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