r/cpp • u/tartaruga232 MSVC user, r/cpp_modules • Mar 16 '26
Implementation of Module Partitions and Standard Conformance
I've spent more than a year now using modules and I found something puzzling with partitions.
I'm using the MSVC compiler (VS 2026 18.4.0) with the following input:
// file A.ixx
export module A;
export import :P0;
export import :P1;
export import :P2;
// file AP0.ixx
export module A:P0;
export struct S
{
int a;
int b;
};
// file AP1.ixx
export module A:P1;
import :P0;
export S foo();
// file AP2.ixx
export module A:P2;
import :P0;
export S bar();
// file AP1.cpp
module A:P1;
S foo()
{
return { 1, 2 };
}
// file AP2.cpp
module A:P2;
S bar()
{
return { 41, 42 };
}
// file main.cpp
import A;
int main()
{
foo();
bar();
}
The resulting program compiles and links fine.
What puzzles me is, when I look at the wording in the standard, it seems to me like this is not covered.
What's particularly interesting is, that it seems like the declarations in AP1.ixx are implicitly imported in AP1.cpp without importing anything (same for AP2.cpp).
For regular modules, this behavior is expected, but I can't seem to find wording for that behavior for partitions. It's like there would be something like an implementation unit for partitions.
I like what the MSVC compiler seems to be doing there. But is this covered by the standard?
If I use that, is it perhaps "off-standard"? What am I missing?
To my understanding, the following would be compliant with the wording of the standard:
// file AP1.cpp
module A;
S foo()
{
return { 1, 2 };
}
// file AP2.cpp
module A;
S bar()
{
return { 41, 42 };
}
But then, a change in the interface of module A would cause a recompilation of both AP1.cpp and AP2.cpp.
With the original code, if I change AP1.ixx, AP2.cpp is not recompiled. This is great, but is this really covered by the standard?
Edit: The compiler is "Version 19.51.36122 for x64 (PREVIEW)"
View all comments
Show parent comment
1
u/38thTimesACharm Mar 17 '26
I'm guessing they wanted to make the developer experience more ergonomic for small- to medium-sized projects. There are a huge number of C++ users out there who never write enough code to care about optimizing compilation times.
A major goal of modules was to make the language look more modern in this regard. Header files and include guards are something users run into almost immediately that just screams "wow, this tool is ancient."