global-module-fragment: module-keyword ; declaration-seq
postfix-expression ( expression-list )whose postfix-expression denotes a dependent name, or for an operator expression whose operator denotes a dependent name, and D is found by name lookup for the corresponding name in an expression synthesized from E by replacing each type-dependent argument or operand with a value of a placeholder type with no associated namespaces or entities, or
const int size = 2; int ary1[size]; // unspecified whether size is decl-reachable from ary1 constexpr int identity(int x) { return x; } int ary2[identity(2)]; // unspecified whether identity is decl-reachable from ary2 template<typename> struct S; template<typename, int> struct S2; constexpr int g(int); template<typename T, int N> S<S2<T, g(N)>> f(); // S, S2, g, and ā::ā are decl-reachable from f template<int N> void h() noexcept(g(N) == N); // g and ā::ā are decl-reachable from hā end example
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; // Nā::āX, N, and ā::ā are decl-reachable from use_Āf return f(x, 123); // Nā::āf is decl-reachable from use_Āf, // Nā::āe is indirectly decl-reachable from use_Āf // because it is decl-reachable from Nā::āf, and // Nā::ād is decl-reachable from use_Āf // because it is decl-reachable from Nā::āf // even though it is not used in this call } template<typename T> int use_g() { N::X x; // Nā::āX, N, and ā::ā are decl-reachable from use_Āg return g((T(), x)); // Nā::āg is not decl-reachable from use_Āg } template<typename T> int use_h() { N::X x; // Nā::āX, N, and ā::ā are decl-reachable from use_Āh return h((T(), x)); // Nā::āh is not decl-reachable from use_Āh, but // Nā::āh is decl-reachable from use_Āh<int> } int k = use_h<int>(); // use_Āh<int> is decl-reachable from k, so // Nā::āh is decl-reachable from k
Module M implementation:
module M; int a = use_f<int>(); // OK int b = use_g<int>(); // error: no viable function for call to g; // g is not decl-reachable from purview of // module M's interface, so is discarded int c = use_h<int>(); // OKā end example