[module.global.frag] (original) (raw)

10 Modules [module]

10.4 Global module fragment [module.global.frag]

[Note 1:

Prior to phase 4 of translation, only preprocessing directives can appear in the declaration-seq ([cpp.pre]).

— _end note_]

A global-module-fragment specifies the contents of theglobal module fragment for a module unit.

The global module fragment can be used to provide declarations that are attached to the global module and usable within the module unit.

A declaration D is decl-reachable from a declaration Sin the same translation unit if

In this determination, it is unspecified

[Note 3:

A discarded declaration is neither reachable nor visible to name lookup outside the module unit, nor in template instantiations whose points of instantiation ([temp.point]) are outside the module unit, even when the instantiation context ([module.context]) includes the module unit.

— _end note_]

[Example 1: const int size = 2;int ary1[size]; constexpr int identity(int x) { return x; } int ary2[identity(2)]; template<typename> struct S;template<typename, int> struct S2;constexpr int g(int);template<typename T, int N>S<S2<T, g(N)>> f(); template<int N> void h() noexcept(g(N) == N); — _end example_]

[Example 2:

Source file "foo.h":namespace N { struct X {};int d();int e();inline int f(X, int = d()) { return e(); } int g(X);int h(X);}

Module M interface:module;#include "foo.h" export module M;template<typename T> int use_f() { N::X x; return f(x, 123); } template<typename T> int use_g() { N::X x; return g((T(), x)); } template<typename T> int use_h() { N::X x; return h((T(), x)); } int k = use_h<int>();

Module M implementation:module M;int a = use_f<int>(); int b = use_g<int>(); int c = use_h<int>(); — _end example_]