[module.private.frag] (original) (raw)
10 Modules [module]
10.5 Private module fragment [module.private.frag]
A private-module-fragment shall appear only in a primary module interface unit ([module.unit]).
A module unit with a private-module-fragmentshall be the only module unit of its module; no diagnostic is required.
[Note 1:
A private-module-fragment ends the portion of the module interface unit that can affect the behavior of other translation units.
A private-module-fragment allows a module to be represented as a single translation unit without making all of the contents of the module reachable to importers.
The presence of a private-module-fragment affects:
- the point by which the definition of an inline function or variable is required ([dcl.inline]),
- the point by which the definition of an exported function with a placeholder return type is required ([dcl.spec.auto]),
- whether a declaration is required not to be an exposure ([basic.link]),
- where definitions for inline functions and templates must appear ([basic.def.odr], [dcl.inline], [temp.pre]),
- the instantiation contexts of templates instantiated before it ([module.context]), and
- the reachability of declarations within it ([module.reach]).
— _end note_]
[Example 1: export module A;export inline void fn_e(); inline void fn_m(); static void fn_s();export struct X;export void g(X *x) { fn_s(); } export X *factory(); module :private;struct X {}; X *factory() { return new X ();} void fn_e() {} void fn_m() {} void fn_s() {} — _end example_]