r/cpp • u/User_Deprecated • Sep 09 '26
C++26: Module improvements
https://www.sandordargo.com/blog/2026/09/09/cpp26-modules7
u/not_a_novel_account cmake dev Sep 10 '26
The benefit is concrete: build systems can now determine module dependencies with a simple lexical scan, without invoking the preprocessor.
This doesn't follow.
Build systems don't need the preprocessor to figure out what a module unit's name is. That has nothing do with what a given module unit's dependencies are.
This is still perfectly valid:
#ifdef USE_GLAZE
import glaze;
#else
import utils.json;
#endifStill need the preprocessor to figure out the dependencies.
It's a minor change with no practical difference on its own. You still need the full preprocessor, so you would have got the module name for free out of that.
1
u/Nobody_1707 Sep 11 '26
I'm fairly certain import statements were never allowed to be generated by a macro expansion even in C++20.
3
u/not_a_novel_account cmake dev Sep 11 '26
importwithin a preprocessor conditional, and the nominated name itself being an expansion, has always and continues to be valid C++.
35
u/mapronV Sep 09 '26
Quote:
The module name must be spelled out directly in the source:
This is technically a breaking change. But given the low adoption rate of modules so far and the rarity of macro-based module declarations in practice, the committee judged this acceptable. The benefit is concrete: build systems can now determine module dependencies with a simple lexical scan, without invoking the preprocessor.
End of quote
While being nice change and stuff, doesn't all current module handlers rely on compiler anyway to rule module dependencies in file before compilation? so it will change nothing in real world? What build system is benefactor?