Files
2025-10-25 03:02:53 +03:00

3.3 KiB

[module.private.frag]

10 Modules [module]

10.5 Private module fragment [module.private.frag]

private-module-fragment:
module-keyword : private ; declaration-seqopt

1

#

A private-module-fragment shall appear only in a primary module interface unit ([module.unit]).

A module unit with a private-module-fragment shall be the only module unit of its module; no diagnostic is required.

2

#

[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]

3

#

[Example 1: export module A;export inline void fn_e(); // error: exported inline function fn_e not defined// before private module fragmentinline void fn_m(); // error: non-exported inline function fn_m not definedstatic void fn_s();export struct X;export void g(X *x) { fn_s(); // OK, call to static function in same translation unit}export X *factory(); // OKmodule :private;struct X {}; // definition not reachable from importers of A X *factory() {return new X ();}void fn_e() {}void fn_m() {}void fn_s() {} — end example]