public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-339] c++: Support module language-decl semantics
@ 2022-05-12 11:16 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2022-05-12 11:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:78c8b0b980341f28de96da518a38bf85bbd24d98
commit r13-339-g78c8b0b980341f28de96da518a38bf85bbd24d98
Author: Nathan Sidwell <nathan@acm.org>
Date: Mon May 9 04:51:32 2022 -0700
c++: Support module language-decl semantics
In modules purview, one can attach a declaration to the global module
(i.e. not the named module in whence the declaration appears), using a
language declaration:
export module Foo;
extern "C++" void *operator new (std::size_t);
This implements those semantics.
gcc/cp/
* parser.cc (cp_parser_linkage_specification): Implement
global module attachment semantics.
gcc/testsuite/
* g++.dg/modules/lang-3_a.C: New.
* g++.dg/modules/lang-3_b.C: New.
* g++.dg/modules/lang-3_c.C: New.
Diff:
---
gcc/cp/parser.cc | 3 +++
gcc/testsuite/g++.dg/modules/lang-3_a.C | 17 +++++++++++++++++
gcc/testsuite/g++.dg/modules/lang-3_b.C | 18 ++++++++++++++++++
gcc/testsuite/g++.dg/modules/lang-3_c.C | 12 ++++++++++++
4 files changed, 50 insertions(+)
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 84f379c7bff..8969ed0076a 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -16189,6 +16189,8 @@ cp_parser_linkage_specification (cp_parser* parser, tree prefix_attr)
linkage = get_identifier (TREE_STRING_POINTER (linkage));
/* We're now using the new linkage. */
+ unsigned saved_module = module_kind;
+ module_kind &= ~MK_ATTACH;
push_lang_context (linkage);
/* Preserve the location of the innermost linkage specification,
@@ -16235,6 +16237,7 @@ cp_parser_linkage_specification (cp_parser* parser, tree prefix_attr)
/* We're done with the linkage-specification. */
pop_lang_context ();
+ module_kind = saved_module;
/* Restore location of parent linkage specification, if any. */
parser->innermost_linkage_specification_location = saved_location;
diff --git a/gcc/testsuite/g++.dg/modules/lang-3_a.C b/gcc/testsuite/g++.dg/modules/lang-3_a.C
new file mode 100644
index 00000000000..1c6fa1fa2e9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/lang-3_a.C
@@ -0,0 +1,17 @@
+// { dg-additional-options "-fmodules-ts -Wno-pedantic" }
+module;
+# 4 __FILE__ 1
+void Quux ();
+# 6 "" 2
+export module bob;
+// { dg-module-cmi bob }
+
+extern "C++"
+{
+export void Bar () {}
+export void Quux ();
+void Baz () {}
+}
+
+// { dg-final { scan-assembler {_Z3Barv:} } }
+// { dg-final { scan-assembler {_Z3Bazv:} } }
diff --git a/gcc/testsuite/g++.dg/modules/lang-3_b.C b/gcc/testsuite/g++.dg/modules/lang-3_b.C
new file mode 100644
index 00000000000..17300ece699
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/lang-3_b.C
@@ -0,0 +1,18 @@
+// { dg-additional-options -fmodules-ts }
+import bob;
+
+void Foo ()
+{
+ Bar ();
+ Baz (); // { dg-error "was not declared" }
+ Quux ();
+}
+
+void Bar ();
+void Baz ();
+
+void Quux ()
+{
+ Bar ();
+ Baz ();
+}
diff --git a/gcc/testsuite/g++.dg/modules/lang-3_c.C b/gcc/testsuite/g++.dg/modules/lang-3_c.C
new file mode 100644
index 00000000000..ca18db72ad8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/lang-3_c.C
@@ -0,0 +1,12 @@
+// { dg-additional-options -fmodules-ts }
+module bob;
+
+void Foo ()
+{
+ Bar ();
+ Baz ();
+}
+
+extern "C++" void Bar ();
+extern "C++" void Baz ();
+
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-12 11:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 11:16 [gcc r13-339] c++: Support module language-decl semantics Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).