You are not logged in.

#1 2015-12-13 13:39:39

The Infinity
Member
Registered: 2014-07-05
Posts: 91
Website

New ABI and std::ios_base::failure

Hi,

We've got the new libstdc++ ABI: https://www.archlinux.org/news/c-abi-change/

When compiling one of my applications, I've run into the following problem:

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    try {
        fstream file;
        file.exceptions(ios_base::failbit | ios_base::badbit);
        file.open("/etc/pacman.conf", ios_base::in);
        string line;
        while(true) {
            getline(file, line);
            cerr << line << endl;
        }
    } catch(const ios_base::failure &e) {
        cerr << "caught std::ios_base::failure - expected behaviour" << endl;
        cerr << e.what() << endl;
    } catch(const exception &e) {
        cerr << "caught any std::exception - this shouldn't happen" << endl;
        cerr << e.what() << endl;
    }
    return 0;
} 

This code only behaves as expected, when using the old ABI because the "old" ios_base::failure is thrown:

g++ -D_GLIBCXX_USE_CXX11_ABI=0 abi_test.cpp -o old_abi && ./old_abi # prints "expected behaviour"
g++ -D_GLIBCXX_USE_CXX11_ABI=1 abi_test.cpp -o new_abi && ./new_abi # prints "shouldn't happen"

Example file: http://martchus.netai.net/download.php?name=abi_test
See also: https://davmac.wordpress.com/2015/08/26 … -just-not/

Can you reproduce the error? How do you deal with it? By simply adding -D_GLIBCXX_USE_CXX11_ABI=0 until the problem is fixed?

Last edited by The Infinity (2015-12-13 19:00:53)

Offline

#2 2015-12-13 23:31:20

crondog
Member
Registered: 2011-04-21
Posts: 130

Re: New ABI and std::ios_base::failure

GCC Devs wrote:

I would suggest not using exceptions with iostreams, they've always been an odd mix anyway.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145

Offline

#3 2015-12-14 13:29:41

The Infinity
Member
Registered: 2014-07-05
Posts: 91
Website

Re: New ABI and std::ios_base::failure

I've already read this thread but I don't agree with the statement:

- I have already used this feature and I guess I'm not the only one. Suggesting to not use it means suggesting to rewrite a lot of code. In my opinion it is unlogical to care about the binary interface when not even the programming interface is backward compatible.
- Using execptions to handle stream errors is not "an odd mix". A lot of programming languages / APIs even force the programmer to handle stream errors in this way (C#, Java, Python, ...).

GCC 5.3 is being released, adjusting target milestone.

Hence they updated the target milestone to 5.4 I guess we can expect the problem to be fixed when 5.4 is released. I think I'll stick with the old ABI till then (forcing it by undefining the macro).

Offline

Board footer

Powered by FluxBB