public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: cygwin@cygwin.com
Subject: Re: [BUG] try..catch does not work if compiled with clang 8.0
Date: Wed, 18 Dec 2019 19:32:00 -0000	[thread overview]
Message-ID: <9f6fe40a-2dda-211f-57bc-d8b05413db4a@SystematicSw.ab.ca> (raw)
In-Reply-To: <016d01d5b5b5$47d6b8a0$d78429e0$@samsung.com>

On 2019-12-18 08:10, Pavel Fedin wrote:
> Well, it turned out more complicated than i thought. Here is the reduced
> reproducer:
> --- cut catch_test.cpp ---
> #include <stdexcept>
> #include <iostream>
> #include <vector>
> #include <string>
> #include <fstream>
> 
> void from_file(const std::string &filepath, std::vector<int8_t> &data);
> 
> int main()
> {
>     try
>     {
>       std::vector<int8_t> data;
> 
>       from_file("no_such_file.bin", data);
>       std::cout << "Success ???" << std::endl;
>     }
>     catch (const std::exception &e)
>     {
>       std::cout << "std::exception: " << e.what() << std::endl;
>     }
> 
>     return 0;
> }
> --- cut catch_test.cpp ---
> --- cut catch_test_2.cpp ---
> #include <stdexcept>
> #include <iostream>
> #include <vector>
> #include <string>
> #include <fstream>
> 
> using namespace std;
> 
> template <typename T> void from_file_impl(const string &filepath, vector<T> &data)
> {
> //  data.clear();
> 
>   std::ifstream ifs(filepath.c_str());
>   if (ifs.rdstate() & ifstream::failbit)
>   {
>     throw std::runtime_error("Error in reading " + filepath);
>   }
> 
> /*  T buffer;
> 
>   while (ifs.read(reinterpret_cast<char *>(&buffer), sizeof(T)))
>   {
>     data.push_back(buffer);
>   }*/
> }
> 
> void from_file(const string &filepath, vector<int8_t> &data) { from_file_impl(filepath, data); }
> --- cut catch_test_2.cpp ---
> --- cut console log ---
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ clang++-8 catch_test.cpp catch_test_2.cpp -g -o catch_test
> 
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ ./catch_test
> 
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ g++.exe catch_test.cpp catch_test_2.cpp -g -o catch_test
> 
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ ./catch_test
> 
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ clang++-5.0 catch_test.cpp catch_test_2.cpp -g -o catch_test
> 
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ ./catch_test
> std::exception: Error in reading no_such_file.bin
> 
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $
> --- cut console log ---
> 
> So, the problem actually reproduces with both clang 8 and gcc (7.4.0 on my 
> system). clang 5 works fine.

Confirmed with clang++ 8, but WJFFM with g++ 7.4.0 and reports exception (below).

Warnings from clang++ and g++:
$ clang++-8/5.0 -g -Og -Wpedantic -Wall -Wextra -o try-catch-stc-1{,.cpp}
try-catch-stc-2.cpp
try-catch-stc-2.cpp:9:78: warning: unused parameter 'data' [-Wunused-parameter]
template <typename T> void from_file_impl(const string &filepath, vector<T> &data)
                                                                             ^
1 warning generated.
$ g++ -g -Og -Wpedantic -Wall -Wextra -o try-catch-stc-1{,.cpp} try-catch-stc-2.cpp
try-catch-stc-2.cpp: In instantiation of ‘void from_file_impl(const string&,
std::vector<T>&) [with T = signed char; std::string = std::basic_string<char>]’:
try-catch-stc-2.cpp:19:34:   required from here
try-catch-stc-2.cpp:9:78: warning: unused parameter ‘data’ [-Wunused-parameter]
 template <typename T> void from_file_impl(const string &filepath, vector<T> &data)
 $ ./try-catch-stc-1
exception: Error in reading no_such_file.bin

>  So, a Windows exception is reported, then the whole thing silently quits.
> I have an impression that it has to do with the bug I previously reported 
> (and someone here claimed he could reproduce it)

Please provide a link to the Cygwin ML message; is it this, confirmed by Takashi
Yano:

	https://cygwin.com/ml/cygwin/2019-10/msg00038.html

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
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

  parent reply	other threads:[~2019-12-18 17:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20191217093504eucas1p14cced4e1f9fcec50e44e9223d1761858@eucas1p1.samsung.com>
2019-12-17 11:04 ` Pavel Fedin
2019-12-17 17:48   ` Brian Inglis
2019-12-17 21:36     ` Csaba Ráduly
2019-12-18  1:50       ` Brian Inglis
2019-12-18 16:23         ` Pavel Fedin
2019-12-18 18:54           ` Dominik Strasser
2019-12-18 19:32           ` Brian Inglis [this message]
2019-12-19 10:30             ` Pavel Fedin
2019-12-19 17:12             ` Pavel Fedin
2019-12-18 17:46 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=9f6fe40a-2dda-211f-57bc-d8b05413db4a@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --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).