delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2022/07/02/16:20:35

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C178A3858C53
Authentication-Results: sourceware.org;
dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=0IwRYD/VC/1WT7vANaX+B6+PQZzF5voFSIqhjvKrk00=;
b=Jlc93ROd8z94iW4LoWQn8Q7GyE/OtN78Ea6OE6QkkW8PPjOzoA2RxeM7GgFxO9mar0
km8EfgK58434BvYmlm1qYUdBkxIfOBSW8xrUxglP7QV9rheuokAgA0GnJ7jRU9Cb+jpv
PF7QEUSPLY1GV7nLMwF7+PBc7rpr7Z4T98WvKu6Nt2gXgh7sZXLMi/kXijfKoFlatzgk
HuTf1+if7GYjqqfB1Sf0oXIqgcq83eJ/kh1V4x48A/jQzOLz4Xo8FInATsYiO8L1Fnmq
aSzS+w5ZFN5ZV4PABKDzUP6tBTo2lFpkVqDoMrdzQG5pOLb5VZanwU2VqslK+9c85Ttz
MJzQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=0IwRYD/VC/1WT7vANaX+B6+PQZzF5voFSIqhjvKrk00=;
b=QnCKNQhCyCPHJ+OL8rRM/beevb/YM2iCmX4qWDyJXZJ47YvBXi2hAppFIOmqa19/8c
tJowxF5xNDeoglX3Ae7Wy/R7Tt/AyJQfhPnVn2goK74TEQpQbpfvVwX522/tAUrAgS38
VFZvn42+9vXEDnITKiIfxrR0hE+R/rHcwg2DrVVnZdGUnHEL97JfuDvslAy6gfjDaB7e
BAG8iheWM7r7BphHzhc0Ohrh8t+XV2ldRMgNIV8EzL/ZE3LIrlfr2+QijQRtGTEwoZZP
Xv/gRN/asKzC73I3ranbbH7A5HlGlxb+YvIAx+S1YpTzKQhaZciiVDlLyWJ7nJz5zHa2
4c/Q==
X-Gm-Message-State: AJIora/imfW813MaidCCDNEuhq1Tf4J248VFk6rojb/2LmD7et7y1Bu2
GpKkmMTkWVRMmpEEDDNJItMfm/IuxsbafcRo4C7yLNffnUIy9w==
X-Google-Smtp-Source: AGRyM1sXAFfBp/zP9wwiKbG+1J9OqsMQr2inZ2edmFFpmi+0icwvZaTfubZifGndJU1j/EGYw6gfFTAFdN1aliRVqJs=
X-Received: by 2002:a1c:ed08:0:b0:39c:80b1:b0b3 with SMTP id
l8-20020a1ced08000000b0039c80b1b0b3mr23474059wmh.134.1656793196292; Sat, 02
Jul 2022 13:19:56 -0700 (PDT)
MIME-Version: 1.0
References: <20220702132158 DOT g6u7wo2lnokgezoc AT lucy DOT dinwoodie DOT org>
In-Reply-To: <20220702132158.g6u7wo2lnokgezoc@lucy.dinwoodie.org>
From: Csaba Raduly <rcsaba AT gmail DOT com>
Date: Sat, 2 Jul 2022 22:19:44 +0200
Message-ID: <CAEhDDbCDj9bKLoJUbi4eOdA+Rx-jnA1eyJkkA583OQqyi_702w@mail.gmail.com>
Subject: Re: Unexpected zero return code from `throw std::runtime_error`
To: cygwin list <cygwin AT cygwin DOT com>
X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,
SPF_HELO_NONE, SPF_PASS, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

On Sat, 2 Jul 2022 at 15:22, Adam Dinwoodie  wrote:
>
> I'm currently experimenting with compiling rdfind for Cygwin, and one of
> the testcases is failing because std::runtime_error is expected to
> result in the compiled program exiting with a non-zero return code,
> but on Cygwin, it just seems to cause the program to terminate with a
> zero return code.
>
> I've attached a simple test case.  Compare the output on Cygwin...
>
>     $ ./test.sh
>     + cat
>     + g++ test.cc
>     + [[ -x a.exe ]]
>     + ./a.exe
>     + rc=0
>     + ((  rc == 0  ))
>     + echo 'Unexpected zero return code from execution'
>     Unexpected zero return code from execution
>     + exit 1
>
> ...with the output from one of my Debian boxes...
>
>     $ ./test.sh
>     + cat
>     + g++ test.cc
>     + [[ -x a.exe ]]
>     + [[ -x a.out ]]
>     + ./a.out
>     terminate called after throwing an instance of 'std::runtime_error'
>       what():  Test error
>     ./test.sh: line 21: 566327 Aborted                 ./a.out
>     + rc=134
>     + ((  rc == 0  ))
>     + echo 'Expected non-zero return code received: 134'
>     Expected non-zero return code received: 134
>     + exit 0
>
> I'm not massively familiar with C++, so I could well be missing
> something obvious, but this seems like an unexpected difference between
> Cygwin and other *nix platforms.  Is this a Cygwin bug, or am I doing
> something wrong?


Works just fine for me, unless I misunderstood something.

$ /cygdrive/c/Users/Csaba/Downloads/test.sh
+ cat
+ g++ test.cc
+ [[ -x a.exe ]]
+ ./a.exe
terminate called after throwing an instance of 'std::runtime_error'
  what():  Test error
/cygdrive/c/Users/Csaba/Downloads/test.sh: line 21:   641 Aborted
           (core dumped) ./a.exe
+ rc=134
+ ((  rc == 0  ))
+ echo 'Expected non-zero return code received: 134'
Expected non-zero return code received: 134
+ exit 0

The if goes in the "else" case because rc is not 0, as it should be.
(shoudn't the condition be $rc == 0 ?)
After

$ diff -u /cygdrive/c/Users/Csaba/Downloads/test.sh test.sh
--- /cygdrive/c/Users/Csaba/Downloads/test.sh   2022-07-02
22:09:21.506377100 +0200
+++ test.sh     2022-07-02 22:15:08.670809700 +0200
@@ -20,7 +20,8 @@
        exit 2
 fi

-if (( rc == 0 )); then
+if [[ $rc == 0 ]]
+then
        echo 'Unexpected zero return code from execution'
        exit 1
 else

I get

$ ./test.sh
+ cat
+ g++ test.cc
+ [[ -x a.exe ]]
+ ./a.exe
terminate called after throwing an instance of 'std::runtime_error'
  what():  Test error
./test.sh: line 21:   660 Aborted                 (core dumped) ./a.exe
+ rc=134
+ [[ 134 == 0 ]]
+ echo 'Expected non-zero return code received: 134'
Expected non-zero return code received: 134
+ exit 0


Csaba
-- 
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformant way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


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