C++20 introduced modules. Any symbol that is not exported in a module has module-internal linkage. While unnamed namespaces provide a mechanism to make definitions inside an unnamed namespace have file-internal linkage. Does this mean unnamed namespaces will become useless in future when modules become common practice in C++ community?
Asked
Active
Viewed 332 times
1 Answers
2
No: since (many) compilers see just one translation unit at a time, it’s still useful for optimization to indicate that an entity cannot be used in any other. It also avoids the possibility of accidental collisions between module units (even if those should be less likely than with broader codebases).

Davis Herring
- 36,443
- 4
- 48
- 76
-
I believe most people will go down the "one-module-per-cpp-file" route. – John Z. Li Mar 31 '21 at 03:48
-
1@JohnZ.Li - You believe wrong. One of the most compelling reasons for introducing modules was the ability to organize multiple logically related translation units together. – StoryTeller - Unslander Monica Mar 31 '21 at 05:54