r/cpp • u/tartaruga232 MSVC user, r/cpp_modules • Apr 13 '26
Let's bite the Bullet: Module Units shouldn't implicitly import anything
https://github.com/abuehl/docs/blob/main/no-implicit-import.mdThe correct fix ... is to attack the root cause and stop implicitly importing the interface of module implementation units.
Adding yet another kind of partition is the wrong way to solve it.
19
Upvotes
7
u/schombert Apr 13 '26
I don't quite follow what your proposed solution would look like in practice. It sounds like you would end up with a module "interface" file for external consumers of the module and an internal module "declarations" file for the various implementation files to refer to for internal functions and types. ... Which sounds a lot like going back to implementation cpp files that include library specific .hpp files combined with a single .hpp file intended for consumers of the library to include. If that analogy holds, what are modules actually adding to the story in that case?
10
u/albeva Apr 13 '26
I used to be so excited about modules. But the more I used them, the less enthused I was. At some point, I converted a whole medium-sized project to use modules... only to fully revert a couple of months later.
2
u/jiixyj Apr 13 '26
Agreed! I'd add an exception though that makes the proposal a little less "breaking". What about if you just say
...and don't import any partition explicitly, the whole primary module interface unit is imported, just like today.
But once you import some partition unit, you make clear that you don't need the whole interface. So
...would stop importing the whole of
M.But maybe that's too "cute"? What do you think?
1
u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions Apr 13 '26
Interesting. I havent used the implicit module naming. I usually have one named exported module as the top level and everything else is just a partition to that module. I think this side steps this issue by not using implicit module importing.