Try to fix g++ 4.x issue with generic_category

This commit is contained in:
Peter Dimov
2017-05-20 18:43:31 +03:00
parent b722a1ebda
commit 2d18f66800
2 changed files with 29 additions and 12 deletions

View File

@ -251,7 +251,18 @@ namespace boost
{
if( *this == generic_category() )
{
return std::generic_category();
std::error_category const & st = std::generic_category();
int ev = ENOENT;
// if the standard generic category works, use it; else not
if( st.equivalent( ev, st.default_error_condition( ev ) ) )
{
// g++ 4.x with libstdc++ 5 installed fails, because the two
// generic categories, v1 and v2, get mixed up
return st;
}
}
return std_cat_;

View File

@ -24,15 +24,28 @@ int main() {}
static void test_generic_category()
{
int ev = ENOENT;
// check whether the standard generic category works
std::error_category const & st0 = std::generic_category();
bool has_roundtrip = st0.equivalent( ev, st0.default_error_condition( ev ) );
//
boost::system::error_category const & bt = boost::system::generic_category();
std::error_category const & st = bt;
BOOST_TEST_EQ( &st, &std::generic_category() );
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
int ev = ENOENT;
// BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) );
if( has_roundtrip )
{
BOOST_TEST_EQ( &st, &std::generic_category() );
}
else
{
BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) );
}
{
boost::system::error_code bc( ev, bt );
@ -60,13 +73,6 @@ static void test_generic_category()
BOOST_TEST_EQ( &sn.category(), &st );
BOOST_TEST( st.equivalent( ev, sn ) );
std::error_condition sn2 = st.default_error_condition( ev );
BOOST_TEST_EQ( sn2.value(), ev );
BOOST_TEST_EQ( &sn2.category(), &st );
BOOST_TEST( st.equivalent( ev, sn2 ) );
}
}