[PATCH] D117295: [clang][sema] Allow unnamed decls in C++20 module export{} blocks
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 25 02:44:52 PST 2022
tbaeder updated this revision to Diff 402813.
tbaeder added a comment.
Limited the change to c++2b
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117295/new/
https://reviews.llvm.org/D117295
Files:
clang/lib/Sema/SemaModule.cpp
clang/test/CXX/module/module.interface/p3.cpp
clang/test/Modules/cxx20-export.cpp
Index: clang/test/Modules/cxx20-export.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/cxx20-export.cpp
@@ -0,0 +1,23 @@
+
+// RUN: %clang_cc1 -std=c++2b -verify %s
+export module testmodule;
+
+export static_assert(true); // expected-error {{static_assert declaration cannot be exported}}
+export; // expected-error {{empty declaration cannot be exported}}
+
+namespace A {};
+
+export {
+#define STR(x) constexpr char x[] = #x;
+ STR(foo);
+#undef STR
+
+ static_assert(true);
+
+ template <typename T> struct X { T t; };
+ template <typename T> X(T) -> X<T>;
+
+ ; // Empty declaration
+
+ using namespace A;
+}
Index: clang/test/CXX/module/module.interface/p3.cpp
===================================================================
--- clang/test/CXX/module/module.interface/p3.cpp
+++ clang/test/CXX/module/module.interface/p3.cpp
@@ -9,12 +9,6 @@
export static_assert(true); // expected-error {{static_assert declaration cannot be exported}}
export using namespace A; // expected-error {{ISO C++20 does not permit using directive to be exported}}
-export { // expected-note 3{{export block begins here}}
- ; // expected-error {{ISO C++20 does not permit an empty declaration to appear in an export block}}
- static_assert(true); // expected-error {{ISO C++20 does not permit a static_assert declaration to appear in an export block}}
- using namespace A; // expected-error {{ISO C++20 does not permit using directive to be exported}}
-}
-
export struct {}; // expected-error {{must be class member}} expected-error {{GNU extension}} expected-error {{does not declare anything}}
export struct {} struct_;
export union {}; // expected-error {{must be declared 'static'}} expected-error {{does not declare anything}}
Index: clang/lib/Sema/SemaModule.cpp
===================================================================
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -615,12 +615,10 @@
return llvm::None;
}
-unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
+static unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
switch (UDK) {
case UnnamedDeclKind::Empty:
case UnnamedDeclKind::StaticAssert:
- // Allow empty-declarations and static_asserts in an export block as an
- // extension.
return InBlock ? diag::ext_export_no_name_block : diag::err_export_no_name;
case UnnamedDeclKind::UsingDirective:
@@ -648,10 +646,16 @@
/// Check that it's valid to export \p D.
static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
- // C++2a [module.interface]p3:
- // An exported declaration shall declare at least one name
- if (auto UDK = getUnnamedDeclKind(D))
- diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+ if (auto UDK = getUnnamedDeclKind(D)) {
+ if (S.getLangOpts().CPlusPlus2b) {
+ if (BlockStart.isInvalid())
+ diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+ } else {
+ // C++2a [module.interface]p3:
+ // An exported declaration shall declare at least one name
+ diagExportedUnnamedDecl(S, *UDK, D, BlockStart);
+ }
+ }
// [...] shall not declare a name with internal linkage.
if (auto *ND = dyn_cast<NamedDecl>(D)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117295.402813.patch
Type: text/x-patch
Size: 3297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220125/10b60f1d/attachment-0001.bin>
More information about the cfe-commits
mailing list