[clang] 6e85d27 - [C++] Don't filter using declaration when we perform qualified look up

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 19:24:52 PDT 2023


Author: Chuanqi Xu
Date: 2023-05-11T10:21:52+08:00
New Revision: 6e85d2708115bc1c7cd1bf1674b64934a3cf6c25

URL: https://github.com/llvm/llvm-project/commit/6e85d2708115bc1c7cd1bf1674b64934a3cf6c25
DIFF: https://github.com/llvm/llvm-project/commit/6e85d2708115bc1c7cd1bf1674b64934a3cf6c25.diff

LOG: [C++] Don't filter using declaration when we perform qualified look up

Close https://github.com/llvm/llvm-project/issues/62174

And this was originally a try to close
https://github.com/llvm/llvm-project/issues/62158.

I don't feel this is the correct fix. I just think it is not bad as an
ad-hoc patch. And let's discuss things in the higher-level in the above
GitHub issue link.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D148506

Added: 
    clang/test/Modules/pr62158.cppm
    clang/test/SemaCXX/pr62174.cpp

Modified: 
    clang/lib/Sema/SemaDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4cdf2982b99d..f499a8658d73 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1821,17 +1821,21 @@ bool Sema::IsRedefinitionInModule(const NamedDecl *New,
   return OldM == NewM;
 }
 
-static bool isUsingDecl(NamedDecl *D) {
+static bool isUsingDeclNotAtClassScope(NamedDecl *D) {
+  if (D->getDeclContext()->isFileContext())
+    return false;
+
   return isa<UsingShadowDecl>(D) ||
          isa<UnresolvedUsingTypenameDecl>(D) ||
          isa<UnresolvedUsingValueDecl>(D);
 }
 
-/// Removes using shadow declarations from the lookup results.
+/// Removes using shadow declarations not at class scope from the lookup
+/// results.
 static void RemoveUsingDecls(LookupResult &R) {
   LookupResult::Filter F = R.makeFilter();
   while (F.hasNext())
-    if (isUsingDecl(F.next()))
+    if (isUsingDeclNotAtClassScope(F.next()))
       F.erase();
 
   F.done();
@@ -6378,10 +6382,6 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
     // containing the two f's declared in X, but neither of them
     // matches.
 
-    // C++ [dcl.meaning]p1:
-    //   [...] the member shall not merely have been introduced by a
-    //   using-declaration in the scope of the class or namespace nominated by
-    //   the nested-name-specifier of the declarator-id.
     RemoveUsingDecls(Previous);
   }
 

diff  --git a/clang/test/Modules/pr62158.cppm b/clang/test/Modules/pr62158.cppm
new file mode 100644
index 000000000000..7a0761df7715
--- /dev/null
+++ b/clang/test/Modules/pr62158.cppm
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/lib.cppm -o %t/lib.pcm
+// RUN: %clang_cc1 -std=c++20 %t/main.cpp -fmodule-file=lib=%t/lib.pcm \
+// RUN:     -verify -fsyntax-only
+
+//--- header.h
+namespace lib::inline __1 {
+template <class>
+inline constexpr bool test = false;
+template <class>
+constexpr bool func() {
+    return false;
+}
+inline constexpr bool non_templ = true;
+} // namespace lib
+
+//--- lib.cppm
+module;
+#include "header.h"
+export module lib;
+
+export namespace lib {
+    using lib::test;
+    using lib::func;
+    using lib::non_templ;
+} // namespace lib
+
+//--- main.cpp
+// expected-no-diagnostics
+import lib;
+
+struct foo {};
+
+template <>
+inline constexpr bool lib::test<foo> = true;
+
+template <>
+constexpr bool lib::func<foo>() {
+    return true;
+}
+
+static_assert(lib::test<foo>);
+static_assert(lib::func<foo>());

diff  --git a/clang/test/SemaCXX/pr62174.cpp b/clang/test/SemaCXX/pr62174.cpp
new file mode 100644
index 000000000000..a5283706ec4f
--- /dev/null
+++ b/clang/test/SemaCXX/pr62174.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify
+// expected-no-diagnostics
+namespace lib {
+    namespace impl {
+        template <class>
+        inline constexpr bool test = false;
+    }
+    using impl::test;
+}
+
+struct foo {};
+
+template <>
+inline constexpr bool lib::test<foo> = true;
+
+static_assert(lib::test<foo>);


        


More information about the cfe-commits mailing list