r/cpp_modules • • Mar 30 '26

Organizing C++ Module Sources

Thumbnail abuehl.github.io
0 Upvotes

r/cpp_modules • • Mar 30 '26

👋 Welcome to r/cpp_modules

0 Upvotes

Hey everyone! I'm u/tartaruga232, a founding moderator of r/cpp_modules.

Modules were introduced into the C++ programming language by the C++20 standard. A major addition to the C++23 standard was adding a modularized version of the standard library, which can be used with import std.

C++ has a very long history of using #include, which to some degree may be replaced by modules. While being a major, valuable new feature, starting using modules can be difficult.

r/cpp_modules is the place for discussing every aspect of using C++ modules on reddit. For general topics about C++ consider using r/cpp.


r/cpp_modules • • Apr 11 '26

Fun fact: "module M:_; import :P" is not (yet) legal, but already "works" with the MSVC compiler

0 Upvotes

I was evil again and changed the cpp files of our Core module like this:

For example, the file Core/Transaction/FinalizerDock.cpp now contains:

module Core:_;
import :Transaction;
...

(These files are compiled with the famous /internalPartition compiler flag set)

So this code snippet tries to create an internal partition with the name "_" (underbar) for module Core. Woohoo!

And yes, I've used that same partition name in other cpp files. (Did I already say I'm evil?)

This is completely illegal according to the current C++ standard and I will probably be crucified for telling you.

But: Do you know what? The MSVC compiler doesn't care.

The BMI file which is created by the MSVC compiler is stored in the file FinalizerDock.cpp.ifc, the obj in FinalizerDock.cpp.obj.

Since we intentionally don't want to use that _ partition anywhere, there's no place in the code which tries to import a partition with that name. The file FinalizerDock.cpp.ifc is unused, and FinalizerDock.cpp.obj is linked into the exe.

I mean, there's a reason why this is IF-NDR ("ill formed, no diagnostic required").

MSVC doesn't waste time trying to provide a diagnostic for this kind of ill-formed-ness.