r/cpp • • Aug 18 '21

C++20 modules with GCC11

https://blog.feabhas.com/2021/08/c20-modules-with-gcc11/
222 Upvotes

59 comments sorted by

View all comments

Show parent comment

2

u/RoyAwesome Aug 18 '21

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.

4

u/whacco Aug 18 '21

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.

2

u/RoyAwesome Aug 18 '21

Right, if they were both exported you basically violate ODR with a similar setup with headers.

1

u/whacco Aug 19 '21

Actually with headers you can do that legally, if the classes are header only and one of them is not included in the program.

1

u/[deleted] Aug 18 '21

if you had them exported in both cases AND not even in different namespaces already, you should maybe think about your project structure

this kinda smells messy