r/cpp • u/tartaruga232 MSVC user, r/cpp_modules • Apr 15 '26
How a Module Should Look Like
https://abuehl.github.io/2026/04/14/how-a-module-should-look-like.htmlThis illustrates the point using real code examples from the Core module of our UML Editor. The presented source code of our Core module is complete.
All published source code examples in the text or linked from it are 100% standard conformant. However, the code contains redundant imports. On purpose. Read the text for why!
(See also my previous posting "Let's bite the Bullet: Module Units shouldn't implicitly import anything" for context).
33
Upvotes
View all comments
Show parent comment
1
u/tartaruga232 MSVC user, r/cpp_modules Apr 16 '26 edited Apr 16 '26
Thanks. Yes I do believe explicit import should be the default. My first knee jerk reaction was also that we would lose ergonomics. But what are those ergonomics exactly? It's true that very simple modules today look simple in the code as you can write
"export module Foo;"in TU #11 and"module Foo;"in TU #12, #13, etc. But that "simplicity" comes at a cost: It hides an important fact and there is a difference between partition units and non-partition units. The former do not implicitly import anything. People are now starting to "abuse" that by using the messy internal partition pattern. The sole reason to use a partition as an implementation unit is then, that it doesn't implicitly import anything. We have a lot of users who are reluctant to use modules and stay using header files, one reason is that they have full control by using header files and they are easy to understand how they work. This implicit import is severely against that long term acquired knowledge. We shouldn't say "go back and use header files". At the very least we need the same clarity and build efficiency with modules as we had with header files.At the minimum we need an additional syntax to the standard for implementation units, which do not implicitly import anything. But does it really make sense to have two syntaxes in the standard?
module Foo; // implicitly imports the interface Foomodule Foo:; // (Note the colon!), doesn't implicitly import anythingThat's the typical reaction of C++: If you have a problem in the standard, we have to live forever with that. Then people complain how bloated C++ is and cruft is never removed from the language.
Seriously: At this low rate of adoption of modules, do we really have a problem which can only be fixed by keeping the problem and add another syntax which doesn't have the problem?
Perhaps this hasn't a snowball's chance in hell, but in theory it would be possible to deprecate the implicit import for C++29. In C++29 we could start allowing
which is currently explicitly prohibited by the standard for reasons no one really knows why but implementations of compiler in practice don't really have a problem with (e.g. current MSVC compiles this fine). Currently (and for C++29) for example the MSVC compiler imports the interface of
Footwice. The standard doesn't prohibit to import a module twice at other situations. Perhaps some compilers emit warnings. But the standard doesn't require a warning.C++29 could specify that
is deprecated in the sense that in a future version of the standard, this will no longer have the side effect of importing the interface of
Fooand we should instead use TU #43. Optionally, we could additionally introduce an additional syntax in C++29which does the same as the old
"module Foo;", which makes the bundling of declaring a module and importing its interface explicit.In C++32, the behavior that
"module Foo;"implicitly importsFoocould then be removed and that wart in the standard would be gone forever.Unfortunately, u/not_a_novel_account has said this doesn't have a snowball's chance in hell. I think that's a pity, but I'm completely unfamiliar with the C++ standardization process.