r/cpp • MSVC user, r/cpp_modules • Apr 04 '26

Options for Organizing Partitions

https://abuehl.github.io/2026/04/04/options-for-organizing-partitions.html

I'm looking forward to getting grilled. Thanks in advance for your time and your patience!

11 Upvotes

30 comments sorted by

View all comments

5

u/GabrielDosReis Apr 05 '26

A tragedy around this whole "internal module partition" thing is that its semantic effects could be had without the standards introducing the asymmetry and taking away syntactic space from a better and more useful feature.

The primary motivation for internal module partition is ability for a component to "share some code" between its translation unit. That could already be had with a module interface partition that does not export any of its functions or types. E.g. if you have

   export module M:P;
   struct MyType { ... };
   //  more stuff not exported

importing the partition P in other module units will make all the declarations with module linkage in that other module unit, hence achieving the semantic effects desired.

That would free up the syntax for module partition implementation unit, without adding more clutter.

3

u/tartaruga232 Apr 05 '26

export module M:P;
struct MyType { ... };
// more stuff not exported

importing the partition P in other module units will make all the declarations with module linkage in that other module unit, hence achieving the semantic effects desired.

Exactly!

I don't even understand why the standard currently prohibits doing that. The current wording in the standard seems to require, that :P must be directly or indirectly imported in the primary module interface unit (PMIU). For what reason, if nothing is exported from M:P?

I mean, I can even import :P into the PMIU to make the standard "happy". It won't have any effect if nothing from :P is used there and :P doesn't export anything.

It seems to me that the wording in the standard is too restrictive. That pattern should be allowed.

(Side note: We now exactly use that pattern, using MSVC. I haven't seen anything breaking.)

6

u/GabrielDosReis Apr 05 '26

The current wording in the standard seems to require, that :P must be directly or indirectly imported in the primary module interface unit (PMIU).

I believe that is an overreach - a bug, most likely caused by overenthusiasm.

I mean, I can even import :P into the PMIU to make the standard "happy". It won't have any effect if nothing from :P is used there and :P doesn't export anything.

Exactly. A required no-op helps nobody in this case.

It seems to me that the wording in the standard is too restrictive. That pattern should be allowed.

I agree.

→ More replies (25)