Describe the bug
locale::id classes are used to lazily assign numbers to facets classes. They have non-trivial constructors and when compiled in debug mode they are not initialized at compile time. This means that the following could happen:
- Some static constructor (std::cin for example) uses locales and causes id assignment for some facets.
- locale::id constructors for this facets are called which reset facet ids to zero.
- The program tries to use locales and different ids are assigned to facets which leads to errors or crashes.
Command-line test case
C:\Temp>type main.cpp
#include <locale>
#include <iostream>
struct S {
size_t id;
S() {
id = std::collate<char>::id;
}
};
S v;
int main() {
std::cout << v.id << std::endl;
std::cout << std::collate<char>::id << std::endl;
}
C:\Temp>cl /EHsc /W4 /WX /MT main.cpp
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.28.29115 для x64
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.
main.cpp
Microsoft (R) Incremental Linker Version 14.28.29115.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:main.exe
main.obj
C:\Temp>main.exe
2
5
Expected behavior
Either compiler must initialize locale::id's at compile time in debug mode or locale::id class should be rewritten to avoid this problem.
STL version
Microsoft Visual Studio Community 2019 Preview Version 16.8.0 Preview 1.0
Additional context
DevCom-256346 | Microsoft-internal VSO-620209 / AB#620209 and VSO-622201 / AB#622201
Describe the bug
locale::id classes are used to lazily assign numbers to facets classes. They have non-trivial constructors and when compiled in debug mode they are not initialized at compile time. This means that the following could happen:
Command-line test case
Expected behavior
Either compiler must initialize locale::id's at compile time in debug mode or locale::id class should be rewritten to avoid this problem.
STL version
Microsoft Visual Studio Community 2019 Preview Version 16.8.0 Preview 1.0Additional context
DevCom-256346 | Microsoft-internal VSO-620209 / AB#620209 and VSO-622201 / AB#622201