[PATCH] D121748: [clang][Sema] Better support for ObjC++ in Sema::LookupName

Alex Langford via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 15 15:40:28 PDT 2022


bulbazord created this revision.
bulbazord added a reviewer: arphaman.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: clang.

`Sema::LookupName` essentially has two possible code paths based on what
language is currently being used. The predicate selecting the code path
is whether or not C++ is being used. In this scenario, the `Scope`
argument that is being passed needs to be not `nullptr` in order to
succeed. In the C/ObjC case, the `Scope` argument can potentially be
`nullptr` and still succeed. In the case where the `Scope` argument is
`nullptr` and you are dealing with Objective-C++ while looking up an
Objective-C name, you will fail where you otherwise should succeed.

This was surfaced when working on Swift/C++ interop. Swift passes
`nullptr` for the `Scope` when looking up some Objective-C name with the
experimental C++ interop option enabled resulting in a failure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121748

Files:
  clang/lib/Sema/SemaLookup.cpp


Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1937,7 +1937,10 @@
 
   LookupNameKind NameKind = R.getLookupKind();
 
-  if (!getLangOpts().CPlusPlus) {
+  if (!getLangOpts().CPlusPlus || getLangOpts().ObjC) {
+    // In the case of Objective-C++, try C++ unqualified name lookup first.
+    if (getLangOpts().CPlusPlus && CppLookupName(R, S))
+      return true;
     // Unqualified name lookup in C/Objective-C is purely lexical, so
     // search in the declarations attached to the name.
     if (NameKind == Sema::LookupRedeclarationWithLinkage) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121748.415611.patch
Type: text/x-patch
Size: 683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220315/1395904e/attachment.bin>


More information about the cfe-commits mailing list