r/cpp • u/not_a_novel_account cmake dev • Jun 01 '26
BMI Compatibility: Testing Build System C++ Modules Support
https://blog.vito.nyc/posts/bmi-compatibility/
68
Upvotes
r/cpp • u/not_a_novel_account cmake dev • Jun 01 '26
View all comments
Show parent comment
4
u/not_a_novel_account cmake dev Jun 02 '26 edited Jun 02 '26
Module units mix the semantics of implementation units and headers, definitions and declarations, into a single file. You can artificially seperate them if you want, and there are advantages to doing so, but it is no longer necessary.
BMIs only deal with declarations. We're not recompiling the module unit, we're extractating declarations from it. ODR isn't in play. This is the same as including a header file and carries the same risks.
When you include a header file, it may have preprocessor logic which changes or alters the declarations it makes available. If these declarations no longer match their definitions, you have a problem.
We have to reinterpret BMIs far less often than we need to reinterpret headers, and have far more control over that process. They never leak macros into one another. They are "safer". The semantics for what needs to happen when we do need to reinterpret them are currently undecided.
Yep, absolutely. There's no defense here. Modules are better than headers, but not a panacea.
The BMI is the part which is an interface, the module unit TU is not an interface, it's an object-file producing TU like any other TU. The module unit TU produces an interface after being interpreted into a BMI. The downstream consumer only sees the BMI, they do not see the inputs which make the BMI, and the BMI does not carry with it the headers or other inputs used to produce it.