From: "Jason Pyeron" <jpyeron@pdinc.us>
To: <cygwin@cygwin.com>
Subject: locale bug?
Date: Mon, 17 May 2021 10:11:25 -0400 [thread overview]
Message-ID: <062101d74b26$85d13600$9173a200$@pdinc.us> (raw)
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.
next reply other threads:[~2021-05-17 14:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-17 14:11 Jason Pyeron [this message]
2021-05-17 17:07 ` Achim Gratz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='062101d74b26$85d13600$9173a200$@pdinc.us' \
--to=jpyeron@pdinc.us \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).