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.
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,
/* 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;
--- /dev/null
+// { 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:} } }
--- /dev/null
+// { 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 ();
+}
--- /dev/null
+// { dg-additional-options -fmodules-ts }
+module bob;
+
+void Foo ()
+{
+ Bar ();
+ Baz ();
+}
+
+extern "C++" void Bar ();
+extern "C++" void Baz ();
+