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) {


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) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to