From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id C178A3858C53 for ; Sat, 2 Jul 2022 20:19:57 +0000 (GMT) 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 Received: by mail-wm1-x32b.google.com with SMTP id u12-20020a05600c210c00b003a02b16d2b8so3420908wml.2 for ; Sat, 02 Jul 2022 13:19:57 -0700 (PDT) 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.g6u7wo2lnokgezoc@lucy.dinwoodie.org> In-Reply-To: <20220702132158.g6u7wo2lnokgezoc@lucy.dinwoodie.org> From: Csaba Raduly Date: Sat, 2 Jul 2022 22:19:44 +0200 Message-ID: Subject: Re: Unexpected zero return code from `throw std::runtime_error` To: cygwin list Content-Type: text/plain; charset="UTF-8" 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@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jul 2022 20:20:00 -0000 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)