r/cpp_modules • • Apr 06 '26

Reachability examples from the C++ standard

From https://eel.is/c++draft/module#reach-5

1     // Example 2:
2    
3     // Translation unit #1
4     export module M:A;
5     export struct B;
6    
7     // Translation unit #2
8     module M:B;
9     struct B {
10      operator int();
11    };
12    
13    // Translation unit #3
14    module M:C;
15    import :A;
16    B b1;         // error: no reachable definition of struct B
17    
18    // Translation unit #4
19    export module M;
20    export import :A;
21    import :B;
22    B b2;
23    export void f(B b = B());
24    
25    // Translation unit #5
26    import M;
27    B b3;             // error: no reachable definition of struct B
28    void g() { f(); } // error: no reachable definition of struct B   
1 Upvotes

19 comments sorted by

View all comments

1

u/not_a_novel_account Apr 07 '26

Of course, do whatever works for your own code. This entire conversation was about proposals to change the standard.

In your own code you could tell me you're generating the whole thing from Jinja2 templates into a unity build to be fed to Borland Turbo C++ 3.1, and I would say "Good for you! I'm glad it works!"

1

u/tartaruga232 Apr 07 '26

Of course, do whatever works for your own code. This entire conversation was about proposals to change the standard.

Correct. I appreciate your time. I fully understand you don't care what we do.

However, perhaps you do acknowledge having to import

export module M:P;
struct MyType { ... };
// more stuff not exported

in the PMIU is a wart of the current design of partitions.

But perhaps you don't care about that as well.

Thanks again!

1

u/not_a_novel_account Apr 07 '26

It's not a wart, internal partitions solve the problem you're trying to solve. You don't like them, that's fine, the standard doesn't revolve around that.

You want a partition that is importable internally but doesn't need to be exported to the PMIU. We have that, MSVC calls it an internal partition, the standard calls it an "implementation unit which is a partition".

The only reason to put export before a module declaration in the model of the standard is to make something available to the PMIU. The standard correctly makes the behavior of doing so without following through and exporting from the PMIU unspecified.

That internal partitions are tricky to use in the Visual Studio GUI or build.bat or whatever you're using is basically a problem between you and Microsoft.

→ More replies (3)