From: JonY <10walls@gmail.com>
To: cygwin@cygwin.com
Subject: Re: iostream exceptions uncaught with CYGWIN GCC/7.3.0
Date: Fri, 02 Nov 2018 10:33:00 -0000 [thread overview]
Message-ID: <f5c36860-aa2f-abe3-e926-be235a153191@gmail.com> (raw)
In-Reply-To: <SN6PR09MB3247A2F93F682588ED4CDD94A5CE0@SN6PR09MB3247.namprd09.prod.outlook.com>
[-- Attachment #1.1: Type: text/plain, Size: 3952 bytes --]
On 11/01/2018 08:42 PM, Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
wrote:
> Hi,
>
> Please consider the following code:
>
> $ cat bug.cpp
> #include <iostream>
>
> using namespace std;
>
> void fun()
> {
> string dummy;
> cin >> dummy;
> }
>
>
> int main()
> {
> cout << "FAIL = 0x" << hex << ios::failbit << endl;
> cout << "EOF = 0x" << hex << ios::eofbit << endl;
> cout << "BAD = 0x" << hex << ios::badbit << endl;
>
> cin.exceptions(ios::eofbit | ios::failbit);
> try {
> fun();
> }
> catch (ios_base::failure&) {
> cerr << "Failure caught!" << endl;
> }
> catch (...) {
> cerr << "Failure uncaught! 0x" << hex << cin.rdstate() << endl;
> }
> return 0;
> }
>
> When this program is compiled and run on Linux, the exception gets caught:
>
> $ uname -a
> Linux iebdev11 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
>
> $ g++ --version
> g++ (GCC) 7.3.0
> Copyright (C) 2017 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> $ g++ -Wall bug.cpp -o bug
>
> $ ./bug < /dev/null
> FAIL = 0x4
> EOF = 0x2
> BAD = 0x1
> Failure caught!
>
> However, same commands on Cygwin, and the exception goes unhandled:
>
> $ uname -a
> CYGWIN_NT-10.0 NCBIPC9135 2.11.1(0.329/5/3) 2018-09-05 10:24 x86_64 Cygwin
>
> $ gcc --version
> gcc (GCC) 7.3.0
> Copyright (C) 2017 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> $ g++ -Wall -o bug bug.cpp
>
> $ ./bug < /dev/null
> FAIL = 0x4
> EOF = 0x2
> BAD = 0x1
> Failure uncaught! 0x6
>
> We've seen this behavior before on Linux too, when the C++ ABI was changed (w/GCC 5.x). I guess CYGWIN packages a version of C++ STDLIB whose ABI is incompatible with default compiler settings.
>
> Here's some explanation of what might be the culprit.
>
> https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html says that:
>
>> Using the default configuration options for GCC the default value of the macro is 1 which causes the new ABI to be active, so to use the old ABI you must explicitly define the macro to 0 before including any library headers.
>> (Be aware that some GNU/Linux distributions configure GCC 5 differently so that the default value of the macro is 0 and users must define it to 1 to enable the new ABI.)
>
>> One exception type does change when using the new ABI, namely std::ios_base::failure. This is necessary because the 2011 standard changed its base class from std::exception to std::system_error, which causes its layout to change. Exceptions due to iostream errors are thrown by a function inside libstdc++.so, so whether the thrown exception uses the old std::ios_base::failure type or the new one depends on the ABI that was active when libstdc++.so was built, not the ABI active in the user code that is using iostreams. This means that for a given build of GCC the type thrown is fixed. In current releases the library throws a special type that can be caught by handlers for either the old or new type, but for GCC 7.1, 7.2 and 7.3 the library throws the new std::ios_base::failure type, and for GCC 5.x and 6.x the library throws the old type. Catch handlers of type std::ios_base::failure will only catch the exceptions if using a newer release, or if the handler is compiled with the same ABI as the type thrown by the library. Handlers for std::exception will always catch iostreams exceptions, because the old and new type both inherit from std::exception.
Cygwin GCC is configured and built with the old C++ ABI, I'm guess
that's the problem?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-11-02 10:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-01 20:42 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2018-11-02 10:33 ` JonY [this message]
2018-11-03 3:53 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
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=f5c36860-aa2f-abe3-e926-be235a153191@gmail.com \
--to=10walls@gmail.com \
--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).