* locale bug?
@ 2021-05-17 14:11 Jason Pyeron
2021-05-17 17:07 ` Achim Gratz
0 siblings, 1 reply; 2+ messages in thread
From: Jason Pyeron @ 2021-05-17 14:11 UTC (permalink / raw)
To: cygwin
While working an updated build of pdfgrep, I ran in to a crash when the environment local was something other than LC_ALL=C.
Looking at http://www.cplusplus.com/reference/locale/locale/locale/ the empty string passed to the constructor should use the environment's default locale and if the “argument” does not represent a valid C-locale in the implementation, runtime_error is thrown.
$ g++ -o bug50 bug50.cc ; echo en_US.UTF-8; LC_ALL="en_US.UTF-8" ./bug50; echo C; LC_ALL=C ./bug50
en_US.UTF-8
Line:8:start
Line:17:exception thrown
Line:19:succeeded using Minimal C locale (the same as locale::classic)
Line:21:about to set global locale
Line:23:done
C
Line:8:start
Line:13:succeeded using The environment's default locale
Line:21:about to set global locale
Line:23:done
$ cat -n bug50.cc
1 #include <iostream>
2 #include <locale>
3
4 using namespace std;
5
6 int main(int argc, char** argv)
7 {
8 cout << "Line:" << __LINE__ << ":start" << endl;
9 locale l;
10 try
11 {
12 l=locale("");
13 cout << "Line:" << __LINE__ << ":succeeded using The environment's default locale" << endl;
14 }
15 catch (exception& e)
16 {
17 cout << "Line:" << __LINE__ << ":exception thrown" << endl;
18 l=locale("C");
19 cout << "Line:" << __LINE__ << ":succeeded using Minimal C locale (the same as locale::classic)" << endl;
20 }
21 cout << "Line:" << __LINE__ << ":about to set global locale" << endl;
22 locale::global(l);
23 cout << "Line:" << __LINE__ << ":done" << endl;
24
25 }
Thoughts? This is out of my knowledge area – never worked with locales in C++ before.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-17 17:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 14:11 locale bug? Jason Pyeron
2021-05-17 17:07 ` Achim Gratz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).