Switched from g++ to clang++; now, exceptions thrown in std::ifstream object upon opening file. try/catch exception doesn't work? ( C++ )

1

I've recently switched to clang++ as my compiler for just this project since my code actually generated a bug in g++ (seg fault). In my project, I need to do some simple file I/O. The following part of my project is now giving me issues; this compiled and ran fine in g++:

std::ifstream m_data_in;
m_data_in.open(filename, std::ios_base::in);

With clang, the above code compiles but the executable "stops working" on the 2nd line above. I would like to be able to show a stack trace but gdb can't find clang++'s compiled programs (I had this working fine with g++) don't work with gdb. However, i do have the outputs from the few modifications of the code.

std::cout << "hi";
std::ifstream m_data_in;
std::cout << "hi";
m_data_in.open(filename, std::ios_base::in);//, std::ios_base::in);
std::cout << "hi";

results in the output:

hihi

with the "stops working" dialog message popping up. I've also run the following to check if there is perhaps an exception being thrown:

std::ifstream m_data_in;
std::string new_line {};

m_data_in.exceptions( std::ifstream::failbit | std::ifstream::badbit );
try 
{
    m_data_in.open(filename, std::ios_base::in);//, std::ios_base::in);
    while ( !m_data_in.eof() ) new_line += m_data_in.get();
}
catch (std::ios_base::failure e )
{
    std::cout << "Exceptions opening/reading file\n";
}

from which i get no console output. Any ideas? Thanks in advance!

EDIT: got the gdb backtrace working!

(gdb) run main
Starting program: D:\Dropbox\Projects\active\kaggle Higgs Boson/main.exe main
[New Thread 6212.0x428]
training.csvhitraining.csv
Program received signal SIGILL, Illegal instruction.
0x6fcc43c3 in libstdc++-6!_ZSt4cout () from c:\MinGW\bin\libstdc++-6.dll
(gdb) bt
#0  0x6fcc43c3 in libstdc++-6!_ZSt4cout () from c:\MinGW\bin\libstdc++-6.dll
#1  0xc81ab000 in ?? ()
#2  0xcc43c06f in ?? ()
#3  0x4172b86f in ?? ()
#4  0x00000c00 in ?? ()
#5  0xcc43c000 in ?? ()
#6  0x28fd206f in ?? ()
#7  0x28fd2000 in ?? ()
#8  0x28fd4000 in ?? ()
#9  0x401e9a00 in ?? ()
#10 0xcc43c000 in ?? ()
#11 0x4043a06f in ?? ()
#12 0x28fd2000 in ?? ()
#13 0x5cf32b00 in ?? ()
#14 0x00000077 in ?? ()
#15 0x76000000 in ?? ()
#16 0x7619a000 in ?? ()
#17 0x5457ce00 in ?? ()
#18 0x523cd377 in ?? ()
#19 0x00000077 in ?? ()
#20 0x00002600 in ?? ()
#21 0x00000000 in ?? ()
(gdb)

EDIT 2: Fixed the catch variable from type 'int' to 'std::ios_base::failure'. Still nothing prints from the catch scope.

c++
exception
gcc
clang
ifstream
asked on Stack Overflow Jul 5, 2014 by user27886 • edited Jul 5, 2014 by user27886

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0