[clang] 2f1555f - [C++20] [Modules] Handle reachability for enum class

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 15 01:06:30 PDT 2022


Author: Chuanqi Xu
Date: 2022-07-15T15:57:04+08:00
New Revision: 2f1555fb11d74376347ee94eb3af258e047f68ce

URL: https://github.com/llvm/llvm-project/commit/2f1555fb11d74376347ee94eb3af258e047f68ce
DIFF: https://github.com/llvm/llvm-project/commit/2f1555fb11d74376347ee94eb3af258e047f68ce.diff

LOG: [C++20] [Modules] Handle reachability for enum class

In previous reachability patch, we missed the case for enum class.
Trying to handle it in this patch and add the corresponding tests.

Added: 
    clang/test/Modules/enum-class.cppm

Modified: 
    clang/lib/Sema/SemaType.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 3edce941c3817..3ab5d26a9a750 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8669,12 +8669,13 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested,
       // of it will do.
       *Suggested = nullptr;
       for (auto *Redecl : ED->redecls()) {
-        if (isVisible(Redecl))
+        if (isAcceptable(Redecl, Kind))
           return true;
         if (Redecl->isThisDeclarationADefinition() ||
             (Redecl->isCanonicalDecl() && !*Suggested))
           *Suggested = Redecl;
       }
+
       return false;
     }
     D = ED->getDefinition();

diff  --git a/clang/test/Modules/enum-class.cppm b/clang/test/Modules/enum-class.cppm
new file mode 100644
index 0000000000000..01ae8c0d8814d
--- /dev/null
+++ b/clang/test/Modules/enum-class.cppm
@@ -0,0 +1,26 @@
+// Checks for reachability for C++11 enum class properly
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify -fsyntax-only
+
+//--- foo.h
+enum class foo {
+    a, b, c
+};
+
+//--- A.cppm
+module;
+#include "foo.h"
+export module A;
+export foo func();
+
+//--- Use.cpp
+// expected-no-diagnostics
+import A;
+void bar() {
+    auto f = func();
+}


        


More information about the cfe-commits mailing list