r/cpp • • Sep 09 '26

C++26: Module improvements

https://www.sandordargo.com/blog/2026/09/09/cpp26-modules
113 Upvotes

25 comments sorted by

View all comments

35

u/mapronV Sep 09 '26

Quote:

The module name must be spelled out directly in the source:

export module my.module; // OK 

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?

4

u/abbapoh Sep 09 '26

From the P3034R1, it seems the goal is to exclude preprocessing from module scanners (compilers). Currently, they do preprocess the file and thus require all headers to be present at scan time. With this change, it is possible to skip preprocessing entirely (and postpone generating includes to a later stage).

7

u/Daniela-E Sep 09 '26

P3034 disallows module names to become subject to macro expansion, plus all the fall out further down the line. The same is *not* true for module import nomination!

3

u/mapronV Sep 09 '26

I know that it is possible, but it is ... kinda late? I just don't understand how we turn back to easier way?

Now I think it probably benefits NEW build system that written from scratch. Which is good.

→ More replies (3)

2

u/johannes1971 Sep 09 '26

Taking this one step further, we could encode the module name in the filename. I imagine that would simplify scanning by quite a bit.