From fe59bbdb3df693bc47285e8dbf200d0225cc4b2c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 24 Jul 2017 04:52:55 +0300 Subject: [PATCH 1/5] Add 03/11 mismatch tests --- test/Jamfile.v2 | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d3ba574..7064eb9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -20,7 +20,38 @@ project : shared:BOOST_SYSTEM_DYN_LINK=1 static:BOOST_SYSTEM_STATIC_LINK=1 ; - + + rule cxx03 ( properties * ) + { + local result ; + + if gcc in $(properties) || clang in $(properties) + { + result = -std=c++03 ; + } + else + { + result = no ; + } + + return $(result) ; + } + + rule cxx11 ( properties * ) + { + local result ; + + if gcc in $(properties) || clang in $(properties) + { + result = -std=c++11 ; + } + else + { + result = no ; + } + + return $(result) ; + } test-suite "system" : [ run error_code_test.cpp @@ -32,6 +63,18 @@ project [ run error_code_test.cpp : : : shared : error_code_test_shared ] + [ run error_code_test.cpp + : : : static @cxx03 : error_code_test_03 + ] + [ run error_code_test.cpp + : : : shared @cxx03 : error_code_test_shared_03 + ] + [ run error_code_test.cpp + : : : static @cxx11 : error_code_test_11 + ] + [ run error_code_test.cpp + : : : shared @cxx11 : error_code_test_shared_11 + ] [ run error_code_user_test.cpp : : : static ] From 2f413abd8d3f6921ab0bec0574fbe6aa7035e517 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 24 Jul 2017 05:15:49 +0300 Subject: [PATCH 2/5] Add more 03/11 mismatch tests --- test/Jamfile.v2 | 18 ++++++++- test/std_mismatch_test.cpp | 80 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/std_mismatch_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7064eb9..77e7ca6 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -41,7 +41,11 @@ project { local result ; - if gcc in $(properties) || clang in $(properties) + if 4.6 in $(properties) + { + result = -std=c++0x ; + } + else if gcc in $(properties) || clang in $(properties) { result = -std=c++11 ; } @@ -105,4 +109,16 @@ project [ run std_interop_test.cpp : : : shared : std_interop_test_shared ] + [ run std_mismatch_test.cpp + : : : static @cxx03 : std_mismatch_test_03 + ] + [ run std_mismatch_test.cpp + : : : shared @cxx03 : std_mismatch_test_shared_03 + ] + [ run std_mismatch_test.cpp + : : : static @cxx11 : std_mismatch_test_11 + ] + [ run std_mismatch_test.cpp + : : : shared @cxx11 : std_mismatch_test_shared_11 + ] ; diff --git a/test/std_mismatch_test.cpp b/test/std_mismatch_test.cpp new file mode 100644 index 0000000..13f7091 --- /dev/null +++ b/test/std_mismatch_test.cpp @@ -0,0 +1,80 @@ + +// Copyright 2017 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +// See library home page at http://www.boost.org/libs/system + +// Avoid spurious VC++ warnings +# define _CRT_SECURE_NO_WARNINGS + +#include +#include + +#if defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) + +int main() +{ + std::cout + << "The version of the C++ standard library being used does not" + " support header so interoperation will not be tested.\n"; +} + +#else + +#include +#include +#include +#include +#include +#include + +static void test_generic_category() +{ + boost::system::error_category const & bt = boost::system::generic_category(); + std::error_category const & st = bt; + + BOOST_TEST_CSTR_EQ( bt.name(), st.name() ); + + int ev = ENOENT; + + BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); + + boost::system::error_code bc( ev, bt ); + std::error_code sc( bc ); + + BOOST_TEST_EQ( bc.message(), sc.message() ); +} + +static void test_system_category() +{ + boost::system::error_category const & bt = boost::system::system_category(); + std::error_category const & st = bt; + + BOOST_TEST_CSTR_EQ( bt.name(), st.name() ); + + int ev = 5; + BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); + + boost::system::error_code bc( ev, bt ); + std::error_code sc( bc ); + + BOOST_TEST_EQ( bc.message(), sc.message() ); +} + +int main() +{ + std::cout + << "The version of the C++ standard library being used" + " supports header so interoperation will be tested.\n"; + + test_generic_category(); + test_system_category(); + + return boost::report_errors(); +} + +#endif From d7ef760af78089a20e39df3dcf6013e6f6f13996 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 24 Jul 2017 05:31:23 +0300 Subject: [PATCH 3/5] Add g++-7, clang-4 to Travis --- .travis.yml | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/.travis.yml b/.travis.yml index b7165c0..93fa51a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -111,6 +111,15 @@ matrix: sources: - ubuntu-toolchain-r-test + - os: linux + env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++1z + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test + - os: linux env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++03 addons: @@ -147,6 +156,50 @@ matrix: sources: - ubuntu-toolchain-r-test + - os: linux + dist: trusty + compiler: g++-7 + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++03 + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + dist: trusty + compiler: g++-7 + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++11 + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + dist: trusty + compiler: g++-7 + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++14 + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + dist: trusty + compiler: g++-7 + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++17 + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + - os: linux env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03 @@ -273,6 +326,50 @@ matrix: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.9 + - os: linux + compiler: clang++-4.0 + env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++03 + addons: + apt: + packages: + - clang-4.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-4.0 + + - os: linux + compiler: clang++-4.0 + env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++11 + addons: + apt: + packages: + - clang-4.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-4.0 + + - os: linux + compiler: clang++-4.0 + env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++14 + addons: + apt: + packages: + - clang-4.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-4.0 + + - os: linux + compiler: clang++-4.0 + env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=c++1z + addons: + apt: + packages: + - clang-4.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-4.0 + - os: osx env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03 From c639237adf6be9f0f52aab5f35c257e4e4209d4c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 24 Jul 2017 05:32:44 +0300 Subject: [PATCH 4/5] Maintain the same error_category class layout in 03/11 mode --- include/boost/system/error_code.hpp | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 1ddb471..ec7e53a 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -262,6 +262,48 @@ namespace boost return std_cat_; } +#else + + // to maintain ABI compatibility between 03 and 11, + // define a class with the same layout + + private: + + class std_category + { + private: + + boost::system::error_category const * pc_; + + public: + + explicit std_category( boost::system::error_category const * pc ): pc_( pc ) + { + } + + virtual ~std_category() {} + + virtual const char * name() const BOOST_NOEXCEPT + { + return pc_->name(); + } + + virtual std::string message( int ev ) const + { + return pc_->message( ev ); + } + + // we can't define default_error_condition or equivalent, + // so if called, it will crash, but that's still better than the + // alternative + }; + + std_category std_cat_; + + public: + + error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {} + #endif public: From a0fb1f2d41c75bc35ec79e35fab936242b7710e2 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 24 Jul 2017 12:29:32 +0300 Subject: [PATCH 5/5] Simplify 03/11 mismatch test because of MinGW; message() doesn't work --- include/boost/system/error_code.hpp | 15 ++++++++------- test/std_mismatch_test.cpp | 19 ++----------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index ec7e53a..0d64b2b 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -288,14 +288,15 @@ namespace boost return pc_->name(); } - virtual std::string message( int ev ) const - { - return pc_->message( ev ); - } + // we can't define message, because (1) it returns an std::string, + // which can be different between 03 and 11, and (2) on mingw, there + // are actually two `message` functions, not one, so it doesn't work + // even if we do - // we can't define default_error_condition or equivalent, - // so if called, it will crash, but that's still better than the - // alternative + // neither can we define default_error_condition or equivalent + + // if these functions are called, it will crash, but that's still + // better than the alternative of having the class layout change }; std_category std_cat_; diff --git a/test/std_mismatch_test.cpp b/test/std_mismatch_test.cpp index 13f7091..37a606b 100644 --- a/test/std_mismatch_test.cpp +++ b/test/std_mismatch_test.cpp @@ -38,15 +38,7 @@ static void test_generic_category() std::error_category const & st = bt; BOOST_TEST_CSTR_EQ( bt.name(), st.name() ); - - int ev = ENOENT; - - BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); - - boost::system::error_code bc( ev, bt ); - std::error_code sc( bc ); - - BOOST_TEST_EQ( bc.message(), sc.message() ); + BOOST_TEST_EQ( bt.name(), st.name() ); } static void test_system_category() @@ -55,14 +47,7 @@ static void test_system_category() std::error_category const & st = bt; BOOST_TEST_CSTR_EQ( bt.name(), st.name() ); - - int ev = 5; - BOOST_TEST_EQ( bt.message( ev ), st.message( ev ) ); - - boost::system::error_code bc( ev, bt ); - std::error_code sc( bc ); - - BOOST_TEST_EQ( bc.message(), sc.message() ); + BOOST_TEST_EQ( bt.name(), st.name() ); } int main()