[PATCH] D128556: Make Objective-C++ match Objective-C's behavior on implicit ivar access when `self` is shadowed

Michael Wyman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 24 13:28:32 PDT 2022


mwyman created this revision.
mwyman added a project: clang.
Herald added a project: All.
mwyman requested review of this revision.
Herald added a subscriber: cfe-commits.

When compiling Objective-C++, name lookup uses the C++ lookup behavior that skips the filtering of non-implicit-self references, and will use a shadowed name that matches the type. As a result implicit ivar access behavior differs between Objective-C and Objective-C++, which can impact local access but also block captures.

This addresses the issue #56193 <https://github.com/llvm/llvm-project/issues/56193> as reported on Github.

Unfortunately it appears the behavior has differed for 11 years (since the original fix for ObjC was applied in 2011).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128556

Files:
  clang/lib/Sema/SemaLookup.cpp


Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1313,6 +1313,9 @@
             R.setShadowed();
             continue;
           }
+        } else if (NameKind == LookupObjCImplicitSelfParam &&
+                   !isa<ImplicitParamDecl>(*I)) {
+          continue;
         } else {
           // We found something in this scope, we should not look at the
           // namespace scope


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128556.439875.patch
Type: text/x-patch
Size: 518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220624/5cdad133/attachment.bin>


More information about the cfe-commits mailing list