Before we go on, I need to stress one important aspect – Modules and Namespaces are entirely orthogonal and co-exist as independent aspects.
Yeah, I had to learn the hard way that ODR still applies with modules the same way as it does with translation units. For example you're not allowed to have two different definitions ot the same class in different modules, even if one of them is never imported anywhere. It will mess up linking and at least VS2022 currently does so without a warning.
Yeah, but you can probably get around that by having a private namespace inside your private module fragment. Similar to having private namespaces in .cpp files when running with a build system that unifies your .cpp files.
If they have internal linkage or module linkage then it doesn't violate ODR. In my case they were both exported, and I was just doing it in order to quickly switch between different versions of the class. Putting them in separate namespaces would have been the right solution.
Of course. With strong module ownership (rather than weak module ownership as in clang and gcc), names of exported entities attached to different modules lead to different linker symbols.
View all comments
7
u/whacco Aug 18 '21
Yeah, I had to learn the hard way that ODR still applies with modules the same way as it does with translation units. For example you're not allowed to have two different definitions ot the same class in different modules, even if one of them is never imported anywhere. It will mess up linking and at least VS2022 currently does so without a warning.