delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/11/01/16:43:09

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:reply-to:to:subject:date:message-id
:content-type:content-transfer-encoding:mime-version; q=dns; s=
default; b=LD2kqmhA/9imUSrTc5FIH9cvoNOQGygw4BoggUSpa8N5frb320Bvy
m8woXcg+TMI+MdoTbJHEZPqJDfsQQ0nMdGSiFIXGujf1DZOh7+e+j+svArPZJm3H
g9QF2x8QyENjXmGeyITaENgbf9oX8qx9SvVBfBArC800JMnIibAg1o=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:reply-to:to:subject:date:message-id
:content-type:content-transfer-encoding:mime-version; s=default;
bh=I+B0KO6IPbiIhXsjLytpwwgK/Co=; b=symiDVs1XripI0E1CWWNKqMYuVCh
qZPifGJTKTUFxcjSu1pf8uqqQf44pTdSzonHv5VEL7NR9vvhO+eOUAi6YWwQi3TL
AwSF7Z3JrD78h5z2ed8ZFL8byT+r4dlaBapsYREeRlfGZcbseBvKbFZg+LLopWR7
4kFxrPeVUOsmRJ0=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_NUMSUBJECT,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=H*F:D*gov, 5x, 71
X-HELO: nihcesxwayst04.hub.nih.gov
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nih.gov; i=@nih.gov; q=dns/txt; s=NIH; t=1541104971; x=1572640971; h=from:to:subject:date:message-id: content-transfer-encoding:mime-version; bh=C3pAo/MQyF+kBZP4XTu0PjJBToniIWGtisH69xz+gLA=; b=QjdNeYirGj1Oodcg0vRbqMZ5DV0uMyszAY1PvCWb6WnOWKdk2P85PGDw NAohzojU10UT7v22DdL47tJCm4ve9sEvQh7WXLQynDvsj/gkVIl8E5xDD NTm3JCe+4JV4/+t3x1dfQ9QNKTNGzc+n/aI6TNNoOlSt3BI2UQ/I38uhi 80rFON/9CK0XOjfNyjUrmOsgY1J2KYqMGVNQdf1tsdoESinVhUGnONdyZ aJmDujTWTK6+kVs9V2FyksKiPrNvp+7JSi6sPAYstR4BQcqatQGZ88E7S 1tFncCXVw44I0lEXVCW2rVu5jENPR5lkDmLiF6gt2Qwbmd5NiIXJbXQyF Q==;
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nih.onmicrosoft.com; s=selector1-ncbi-nlm-nih-gov; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C3pAo/MQyF+kBZP4XTu0PjJBToniIWGtisH69xz+gLA=; b=OlsXIZqI3U8P2gb6GfhqhWTxS3EtsjXB8SxACZfdkN+D2ecHMGIdgEhpC78QFr9Qx+rzFGko8961EnDeBCOjwaNl17LfZD/f7F4+jgByHl8TeJ99ChXV3hIQDmo2flbxE8Exo2LB5/o0Y/Bl8sLHXV2WpYZVXs3xV4gok/lIMBA=
From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin" <cygwin AT cygwin DOT com>
Reply-To: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr AT ncbi DOT nlm DOT nih DOT gov>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: iostream exceptions uncaught with CYGWIN GCC/7.3.0
Date: Thu, 1 Nov 2018 20:42:36 +0000
Message-ID: <SN6PR09MB3247A2F93F682588ED4CDD94A5CE0@SN6PR09MB3247.namprd09.prod.outlook.com>
authentication-results: spf=none (sender IP is ) smtp.mailfrom=lavr AT ncbi DOT nlm DOT nih DOT gov;
MIME-Version: 1.0
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id wA1Kh5Xn002724

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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019