Throwing std::ios_base::failure on formatted input with gcc 6.2

Martin Sebor msebor@gmail.com
Fri Oct 28 15:58:00 GMT 2016


On 10/27/2016 08:34 AM, Jonathan Wakely wrote:
> On 27 October 2016 at 15:30, Edward Diener
> <eldlistmailingz@tropicsoft.com> wrote:
>> On 10/27/2016 10:00 AM, Jonathan Wakely wrote:
>>>
>>> On 27 October 2016 at 14:52, Edward Diener wrote:
>>>>
>>>> It sounds like you are also saying that there is no way to catch the old
>>>> type, even if I wanted to, since the header file declaration has the
>>>> decorated attribute.
>>>
>>>
>>> No, the attribute is only present conditionally, see
>>> https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
>>>
>>> If you compile with _GLIBCXX_USE_CXX11_ABI defined to zero then you
>>> get the declaration of the old type (and the old COW std::string, and
>>> the old std::list with O(n) size()).
>>>
>>
>> Thanks ! IMO clearly you should be throwing the std::ios_base::failure which
>> corresponds to the _GLIBCXX_USE_CXX11_ABI macro setting being used.
>
> The exception is thrown from code inside libstdc++.so, which is
> already compiled and can't be affected by a macro defined when you
> #include <iostream>.

I wonder if a trick along the lines of ios_base::Init could do it,
say ios_base::FailureInit.  The class ctor would set a value that
the library checked before throwing an ios_base::failure to decide
which of the two types to throw.

It would have to be a program-wide setting (i.e., a program would
have to #define _GLIBCXX_USE_CXX11_ABI to the same value in every
translation unit).

Martin



More information about the Gcc-help mailing list