This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: [BUG] try..catch does not work if compiled with clang 8.0
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