* Re: iostream exceptions uncaught with CYGWIN GCC/7.3.0
@ 2018-11-03 3:53 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
0 siblings, 0 replies; 3+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin @ 2018-11-03 3:53 UTC (permalink / raw)
To: cygwin; +Cc: JonY
> Cygwin GCC is configured and built with the old C++ ABI, I'm guess that's the problem?
The problem is that it does not work correctly because G++ and its run-time are not consistent.
GCC doc says version 7.x uses new ABI by default, so I'd guess that's the C++ stdlib which was built with the old ABI -- i.e. the other way around.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 3+ messages in thread
* iostream exceptions uncaught with CYGWIN GCC/7.3.0
@ 2018-11-01 20:42 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2018-11-02 10:33 ` JonY
0 siblings, 1 reply; 3+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin @ 2018-11-01 20:42 UTC (permalink / raw)
To: 'cygwin@cygwin.com'
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.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: iostream exceptions uncaught with CYGWIN GCC/7.3.0
2018-11-01 20:42 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
@ 2018-11-02 10:33 ` JonY
0 siblings, 0 replies; 3+ messages in thread
From: JonY @ 2018-11-02 10:33 UTC (permalink / raw)
To: cygwin
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-03 3:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-03 3:53 iostream exceptions uncaught with CYGWIN GCC/7.3.0 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
-- strict thread matches above, loose matches on Subject: below --
2018-11-01 20:42 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2018-11-02 10:33 ` JonY
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).