[Bug libstdc++/67620] New: _GLIBCXX_USE_CXX11_ABI=1 fails to catch ios_base::failure

cctsai57 at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Sep 18 07:27:00 GMT 2015


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

            Bug ID: 67620
           Summary: _GLIBCXX_USE_CXX11_ABI=1 fails to catch
                    ios_base::failure
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cctsai57 at gmail dot com
  Target Milestone: ---

#include <iostream>
#include <fstream>
#include <typeinfo>
using namespace std;

int main()
{
    ifstream f;
    f.exceptions(ifstream::failbit);

    try {
      f.open("file_does_not_exit");// throw ios_base::failure
    }
    catch (const ios_base::failure &iof)
    {
        // g++ -std=gnu++11 -D_GLIBCXX_USE_CXX11_ABI=0
        cout << "typeid(iof) : " << typeid(iof).name() << '\n';
    }
    catch (const exception &ex)
    {
        // g++ -std=gnu++11 -D_GLIBCXX_USE_CXX11_ABI=1. Bug? Why?
        cout << "typeid(ex)  : " << typeid(ex).name() << '\n';
    }
}

$ g++ -std=gnu++11 -D_GLIBCXX_USE_CXX11_ABI=0 a.cpp -static && ./a.out
typeid(iof) : NSt8ios_base7failureE
$ g++ -std=gnu++11 -D_GLIBCXX_USE_CXX11_ABI=1 a.cpp -static && ./a.out
typeid(ex)  : NSt8ios_base7failureE

Description:
Let `f.open()' throw `ios_base::failure'.  If compiled with
-D_GLIBCXX_USE_CXX11_ABI=1, the above code fails to catch `ios_base::failure',
but `exception' insead.

gcc version:
gcc version 5.2.1 20150917 (GCC)
gcc version 6.0.0 20150917 (experimental) (GCC)



More information about the Gcc-bugs mailing list