On 10/10/2017 09:32, Andrey Semashev via Boost wrote:
[...]
Is there really no guarantee that category always get the same address across TUs ?
It will have the same address as long as get_basic_error_category() is called within the same module (dll, so, exe, etc.) If this function is compiled in different modules then there will be multiple instances of the category with different addresses.
On Linux and probably other Unix-like systems this can be solved by exporting the category instance, which is the default. I don't think this can be done on Windows - you'd have to export get_basic_error_category for that instead and it will make this code less friendly to header-only libraries.
Thanks for these explanations. Is there any unit-tests or are any open program relying on the uniqueness of error_category across modules ? Am 10.10.2017 um 10:21 schrieb Groke, Paul via Boost:
[...] And even if the "same address" thing was solvable (which I think it is, although not pretty and it would require interface changes), there is the problem with unloading DLLs/SOs. You'd have to pin every module that contains error categories. Which IMO is a side effect that you really don't expect and want, especially from a header-only library.
I must be missing something about internal linkage. This problem should already exists with the current implementation no ? If you have an error_category singleton instance in a TU, then unloading a dll containing this TU should also lead to having the error_category refer to some incorrect memory location then. Do you know of any example code doing this ? -- Damien Buhl Software Developer +33 6 77 43 10 05