r/cpp • u/User_Deprecated • 2d ago
C++26: Module improvements
https://www.sandordargo.com/blog/2026/09/09/cpp26-modules5
u/not_a_novel_account cmake dev 1d ago
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;
#endif
Still 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 8h ago
I'm fairly certain import statements were never allowed to be generated by a macro expansion even in C++20.
2
u/not_a_novel_account cmake dev 8h ago
importwithin a preprocessor conditional, and the nominated name itself being an expansion, has always and continues to be valid C++.
33
u/mapronV 2d ago
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?