
13 Jan
2018
13 Jan
'18
3:20 p.m.
Andrey Semashev wrote:
I don't think the standard requires this implementation. `system_category()` may return a pointer to a global caregory instance, which is initialized before `main`.
You're not prohibited from calling system_category() before main, so it has to work.
You can see for yourself what happens in practice today: https://godbolt.org/g/1TfPQw The g++/clang++ generated code looks cleaner than that, but it's because it doesn't include system_category(). Here it is in libc++: https://github.com/llvm-mirror/libcxx/blob/master/src/system_error.cpp#L211 MS's code is even more convoluted because their <system_error> works during process shutdown, after static destruction. But the magic static cost is the same in either case.