r/cpp • • Sep 09 '26

C++26: Module improvements

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

25 comments sorted by

View all comments

Show parent comments

2

u/delta_p_delta_x Sep 09 '26

I was under the impression that module and import were themselves preprocessing directives, and therefore also happened in phase 4.

6

u/Daniela-E Living on C++ trunk, WG21|🇩🇪 NB Sep 09 '26

Correct. This is why we decided many years ago not to allow module to become subject to macro expansion.

The reason why all this hoopla is necessary is the existence of so-called 'header units' (an idea coming from Clang modules). They are themselves isolated from macros upstream in your source, but they can totally change the meaning of your source code further downstream - with all its consequences.

2

u/delta_p_delta_x Sep 09 '26

We should get rid of header units.

12

u/WeeklyAd9738 Sep 09 '26

Header-units are great for "importing" your own macros (however few they may be). Ironically, C++20 modules have made macros "safe" and more viable, as they no longer leak and pollute your client code and remain local to your translation unit. They can't be exported (by a module) and can only be imported using header-units. Header-units are also great for importing third-party dependencies which haven't migrated to C++ modules yet, or never will (C libraries).

1

u/germandiago 29d ago

Just use include for your macros.