2017-06-25 19:29:32 +02:00
|
|
|
#define _GLIBCXX_USE_CXX11_ABI 0
|
|
|
|
// include libstd++ specific header <bits/c++config.h> containing __GLIBCXX__
|
2017-06-01 11:29:33 +02:00
|
|
|
// without including ios already (must be included after setting _GLIBCXX_USE_CXX11_ABI)
|
2017-06-25 19:29:32 +02:00
|
|
|
#include <cstddef>
|
2017-06-01 11:29:33 +02:00
|
|
|
|
2017-01-19 21:57:55 +01:00
|
|
|
// ensure the old ABI is used under libstd++ < 7 and the new ABI under libstd++ >= 7
|
2018-04-14 14:48:36 +02:00
|
|
|
// (because libstdc++ < 7 throws the old ios_base::failure and libstdc++ >= 7 the new one)
|
2018-04-14 14:43:35 +02:00
|
|
|
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 7
|
2017-06-25 19:29:32 +02:00
|
|
|
#undef _GLIBCXX_USE_CXX11_ABI
|
2017-01-19 21:57:55 +01:00
|
|
|
#define _GLIBCXX_USE_CXX11_ABI 1
|
|
|
|
#endif
|
2016-08-29 15:35:48 +02:00
|
|
|
|
|
|
|
#include "./catchiofailure.h"
|
|
|
|
|
|
|
|
#include <ios>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace IoUtilities {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Provides a workaround for GCC Bug 66145.
|
|
|
|
* \returns Returns the error message.
|
|
|
|
* \throws Throws the current exception if it is not std::ios_base::failure.
|
2018-04-14 14:48:36 +02:00
|
|
|
* \remarks
|
|
|
|
* - GCC Bug 66145 is "resolved", but the story continues with GCC Bug 85222.
|
|
|
|
* - However, the bug finally got fixed for 7.4 and 8.1 so this workaround can be
|
|
|
|
* dropped in the next major release which also drops support for older libstdc++
|
|
|
|
* versions.
|
|
|
|
* \sa
|
|
|
|
* - initial bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66145
|
|
|
|
* - change introduced in libstdc++ 7: https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/src/c%2B%2B11/functexcept.cc?r1=244498&r2=244497&pathrev=244498
|
|
|
|
* - follow-up bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85222
|
|
|
|
* - final fix: https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=259352
|
2016-08-29 15:35:48 +02:00
|
|
|
*/
|
|
|
|
const char *catchIoFailure()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
throw;
|
2017-05-01 03:13:11 +02:00
|
|
|
} catch (const ios_base::failure &e) {
|
2016-08-29 15:35:48 +02:00
|
|
|
return e.what();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2018-04-14 14:48:36 +02:00
|
|
|
* \brief Throws an std::ios_base::failure with the specified message.
|
|
|
|
* \sa catchIoFailure()
|
2016-08-29 15:35:48 +02:00
|
|
|
*/
|
|
|
|
void throwIoFailure(const char *what)
|
|
|
|
{
|
|
|
|
throw ios_base::failure(what);
|
|
|
|
}
|
2017-09-17 21:45:23 +02:00
|
|
|
} // namespace IoUtilities
|