<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56193>56193</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Objective-C++ implicit ivar access uses local `self` shadow rather than method's implicit `self`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mwyman
</td>
</tr>
</table>
<pre>
C++ skips the Objective-C name lookup behavior that [filters non-implicit-self](https://github.com/llvm/llvm-project/blob/7bfad7b9d8f978fa43a8d6112f7eb2462c28f6a0/clang/lib/Sema/SemaLookup.cpp#L1984-L1985), and will instead find local variables that shadow `self`:
```objective-c
__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](https://github.com/llvm/llvm-project/blob/7bfad7b9d8f978fa43a8d6112f7eb2462c28f6a0/clang/lib/Sema/SemaLookup.cpp#L1316)).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVE2PozgQ_TXkUgoiJoRw4NCdaKSRRjOHXWmOkTFF8LaxkW3SO_9-y4Yk9Mxc5raShYVdfvXq41Vj2h_1KWGvtMC9ydGB7xG-Nf-g8PKG2xNoPiAoY96mERrs-U0aS0bcQ1K8dlJ5tA600Vs5jEoK6bcOVZcU54Qde-9Hl-QvCftE6yp9PzWpMAP9KHW7b9vRmuCPfhtlGtrKpuNt2VTtsavKY8f3OT-2h92OdSU2bH9ggh27A8_IVCi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