diff --git a/include/boost/system/system_error.hpp b/include/boost/system/system_error.hpp index fcc4f27..7b20cd9 100644 --- a/include/boost/system/system_error.hpp +++ b/include/boost/system/system_error.hpp @@ -35,17 +35,7 @@ private: r += ": "; } - r += ec.message(); - - if( ec.has_location() ) - { - r += " ["; - r += ec.to_string(); - r += " at "; - r += ec.location().to_string(); - r += "]"; - } - + r += ec.what(); return r; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 902feff..bab504b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -108,6 +108,7 @@ boost_test(TYPE run SOURCES std_interop_test10.cpp) boost_test(TYPE run SOURCES ec_location_test2.cpp) boost_test(TYPE run SOURCES ec_what_test.cpp) +boost_test(TYPE run SOURCES system_error_test3.cpp) # result diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 75f6684..cde8abd 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -130,6 +130,7 @@ run std_interop_test10.cpp ; run ec_location_test2.cpp ; run ec_what_test.cpp ; +run system_error_test3.cpp ; # result diff --git a/test/quick.cpp b/test/quick.cpp index 58c7d76..77e21d1 100644 --- a/test/quick.cpp +++ b/test/quick.cpp @@ -37,7 +37,7 @@ int main() boost::system::system_error x( bc, "prefix" ); BOOST_TEST_EQ( x.code(), bc ); - BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.message() ); + BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() ); return boost::report_errors(); } diff --git a/test/system_error_test.cpp b/test/system_error_test.cpp index d8e39e7..97fc677 100644 --- a/test/system_error_test.cpp +++ b/test/system_error_test.cpp @@ -81,27 +81,25 @@ int main( int, char *[] ) system_error c6_0( 0, system_category(), "c6_0" ); system_error c6_1( 1, system_category(), "c6_1" ); - TEST( c1_0, 0, "The operation completed successfully" ); - TEST( c1_1, 1, "Incorrect function" ); - TEST( c1_2u, 2, "The system cannot find the file specified" ); + TEST( c1_0, 0, "The operation completed successfully [system:0]" ); + TEST( c1_1, 1, "Incorrect function [system:1]" ); + TEST( c1_2u, 2, "The system cannot find the file specified [system:2]" ); - TEST( c2_0, 0, "c2_0: The operation completed successfully" ); - TEST( c2_1, 1, "c2_1: Incorrect function" ); + TEST( c2_0, 0, "c2_0: The operation completed successfully [system:0]" ); + TEST( c2_1, 1, "c2_1: Incorrect function [system:1]" ); - TEST( c3_0, 0, "c3_0: The operation completed successfully" ); - TEST( c3_1, 1, "c3_1: Incorrect function" ); + TEST( c3_0, 0, "c3_0: The operation completed successfully [system:0]" ); + TEST( c3_1, 1, "c3_1: Incorrect function [system:1]" ); - TEST( c4_0, 0, "The operation completed successfully" ); - TEST( c4_1, 1, "Incorrect function" ); - TEST( c4_2u, 2, "The system cannot find the file specified" ); + TEST( c4_0, 0, "The operation completed successfully [system:0]" ); + TEST( c4_1, 1, "Incorrect function [system:1]" ); + TEST( c4_2u, 2, "The system cannot find the file specified [system:2]" ); - TEST( c5_0, 0, "c5_0: The operation completed successfully" ); - TEST( c5_1, 1, "c5_1: Incorrect function" ); + TEST( c5_0, 0, "c5_0: The operation completed successfully [system:0]" ); + TEST( c5_1, 1, "c5_1: Incorrect function [system:1]" ); - TEST( c6_0, 0, "c6_0: The operation completed successfully" ); - TEST( c6_1, 1, "c6_1: Incorrect function" ); + TEST( c6_0, 0, "c6_0: The operation completed successfully [system:0]" ); + TEST( c6_1, 1, "c6_1: Incorrect function [system:1]" ); return ::boost::report_errors(); } - - diff --git a/test/system_error_test3.cpp b/test/system_error_test3.cpp new file mode 100644 index 0000000..e5b2da5 --- /dev/null +++ b/test/system_error_test3.cpp @@ -0,0 +1,42 @@ +// Copyright 2021 Peter Dimov +// Distributed under the Boost Software License, Version 1.0 +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +namespace sys = boost::system; + +int main() +{ + { + sys::error_code ec( 5, sys::generic_category() ); + sys::system_error x1( ec ); + + BOOST_TEST_EQ( std::string( x1.what() ), ec.what() ); + } + + { + BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION; + + sys::error_code ec( 5, sys::system_category(), &loc ); + sys::system_error x1( ec, "prefix" ); + + BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + ec.what() ); + } + + { + sys::system_error x1( 5, sys::generic_category() ); + + BOOST_TEST_EQ( std::string( x1.what() ), sys::error_code( 5, sys::generic_category() ).what() ); + } + + { + sys::system_error x1( 5, sys::system_category(), "prefix" ); + + BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + sys::error_code( 5, sys::system_category() ).what() ); + } + + return boost::report_errors(); +}