From 0e78e219f55d95b7fc0042d150ea03089aa58a78 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 02:43:20 +0300 Subject: [PATCH 1/8] Make default constructors constexpr --- .../boost/smart_ptr/detail/shared_count.hpp | 6 +- .../smart_ptr/enable_shared_from_this.hpp | 4 +- include/boost/smart_ptr/shared_ptr.hpp | 4 +- include/boost/smart_ptr/weak_ptr.hpp | 2 +- test/Jamfile.v2 | 3 + test/sp_constexpr_test.cpp | 71 +++++++++++++++++++ test/sp_constexpr_test2.cpp | 53 ++++++++++++++ 7 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 test/sp_constexpr_test.cpp create mode 100644 test/sp_constexpr_test2.cpp diff --git a/include/boost/smart_ptr/detail/shared_count.hpp b/include/boost/smart_ptr/detail/shared_count.hpp index 9813842..7f375e8 100644 --- a/include/boost/smart_ptr/detail/shared_count.hpp +++ b/include/boost/smart_ptr/detail/shared_count.hpp @@ -54,7 +54,7 @@ namespace boost namespace movelib { - template< class T, class D > class unique_ptr; +template< class T, class D > class unique_ptr; } // namespace movelib @@ -118,7 +118,7 @@ private: public: - shared_count(): pi_(0) // nothrow + BOOST_CONSTEXPR shared_count(): pi_(0) // nothrow #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) , id_(shared_count_id) #endif @@ -517,7 +517,7 @@ private: public: - weak_count(): pi_(0) // nothrow + BOOST_CONSTEXPR weak_count(): pi_(0) // nothrow #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) , id_(weak_count_id) #endif diff --git a/include/boost/smart_ptr/enable_shared_from_this.hpp b/include/boost/smart_ptr/enable_shared_from_this.hpp index 07e8b8f..fc4de0b 100644 --- a/include/boost/smart_ptr/enable_shared_from_this.hpp +++ b/include/boost/smart_ptr/enable_shared_from_this.hpp @@ -26,11 +26,11 @@ template class enable_shared_from_this { protected: - enable_shared_from_this() BOOST_SP_NOEXCEPT + BOOST_CONSTEXPR enable_shared_from_this() BOOST_SP_NOEXCEPT { } - enable_shared_from_this(enable_shared_from_this const &) BOOST_SP_NOEXCEPT + BOOST_CONSTEXPR enable_shared_from_this(enable_shared_from_this const &) BOOST_SP_NOEXCEPT { } diff --git a/include/boost/smart_ptr/shared_ptr.hpp b/include/boost/smart_ptr/shared_ptr.hpp index 6f5810d..47d8339 100644 --- a/include/boost/smart_ptr/shared_ptr.hpp +++ b/include/boost/smart_ptr/shared_ptr.hpp @@ -345,13 +345,13 @@ public: typedef typename boost::detail::sp_element< T >::type element_type; - shared_ptr() BOOST_SP_NOEXCEPT : px( 0 ), pn() + BOOST_CONSTEXPR shared_ptr() BOOST_SP_NOEXCEPT : px( 0 ), pn() { } #if !defined( BOOST_NO_CXX11_NULLPTR ) - shared_ptr( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn() + BOOST_CONSTEXPR shared_ptr( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn() { } diff --git a/include/boost/smart_ptr/weak_ptr.hpp b/include/boost/smart_ptr/weak_ptr.hpp index 391eac9..54d9ef3 100644 --- a/include/boost/smart_ptr/weak_ptr.hpp +++ b/include/boost/smart_ptr/weak_ptr.hpp @@ -32,7 +32,7 @@ public: typedef typename boost::detail::sp_element< T >::type element_type; - weak_ptr() BOOST_SP_NOEXCEPT : px(0), pn() + BOOST_CONSTEXPR weak_ptr() BOOST_SP_NOEXCEPT : px(0), pn() { } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index a6f6b0c..3037a44 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -213,6 +213,9 @@ import testing ; [ run atomic_sp_test.cpp ] + [ run sp_constexpr_test.cpp ] + [ run sp_constexpr_test2.cpp ] + [ run local_sp_test.cpp ] [ run lsp_array_test.cpp ] [ run lsp_array_n_test.cpp ] diff --git a/test/sp_constexpr_test.cpp b/test/sp_constexpr_test.cpp new file mode 100644 index 0000000..1d345ea --- /dev/null +++ b/test/sp_constexpr_test.cpp @@ -0,0 +1,71 @@ +// +// sp_constexpr_test.cpp +// +// 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 +// + +#include + +#if defined( BOOST_NO_CXX11_CONSTEXPR ) + +int main() +{ +} + +#else + +#include +#include +#include +#include + +struct X: public boost::enable_shared_from_this +{ +}; + +struct Z +{ + Z(); +}; + +static Z z; + +static boost::shared_ptr p1; +static boost::weak_ptr p2; + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + static boost::shared_ptr p3( nullptr ); +#endif + +Z::Z() +{ + p1.reset( new X ); + p2 = p1; +#if !defined( BOOST_NO_CXX11_NULLPTR ) + p3.reset( new X ); +#endif +} + +int main() +{ + BOOST_TEST( p1.get() != 0 ); + BOOST_TEST_EQ( p1.use_count(), 1 ); + + BOOST_TEST_EQ( p2.use_count(), 1 ); + BOOST_TEST_EQ( p2.lock(), p1 ); + +#if !defined( BOOST_NO_CXX11_NULLPTR ) + + BOOST_TEST( p3.get() != 0 ); + BOOST_TEST_EQ( p3.use_count(), 1 ); + +#endif + + return boost::report_errors(); +} + +#endif // #if defined( BOOST_NO_CXX11_CONSEXPR ) diff --git a/test/sp_constexpr_test2.cpp b/test/sp_constexpr_test2.cpp new file mode 100644 index 0000000..4e5cf37 --- /dev/null +++ b/test/sp_constexpr_test2.cpp @@ -0,0 +1,53 @@ +// +// sp_constexpr_test2.cpp +// +// 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 +// + +#include + +#if defined( BOOST_NO_CXX11_CONSTEXPR ) + +int main() +{ +} + +#else + +#include +#include +#include +#include + +struct X: public boost::enable_shared_from_this +{ + int v_; + + constexpr X() BOOST_NOEXCEPT: v_( 1 ) + { + } +}; + +struct Z +{ + Z(); +}; + +static Z z; +static X x; + +Z::Z() +{ + BOOST_TEST_EQ( x.v_, 1 ); +} + +int main() +{ + return boost::report_errors(); +} + +#endif // #if defined( BOOST_NO_CXX11_CONSEXPR ) From c1d72af0a431f9588b85f11322c35b5d30739647 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 03:11:59 +0300 Subject: [PATCH 2/8] Add g++ 7, clang++ 4 to Travis --- .travis.yml | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/.travis.yml b/.travis.yml index ad762ed..8dad3ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -146,6 +146,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 @@ -272,6 +316,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 aef27128f2ae48331f374f9177eacde0037ba02a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 03:32:32 +0300 Subject: [PATCH 3/8] Add feature branch testing, matrix to Appveyor --- .travis.yml | 2 +- appveyor.yml | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8dad3ce..f7ff0dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Copyright 2016 Peter Dimov +# Copyright 2016, 2017 Peter Dimov # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) diff --git a/appveyor.yml b/appveyor.yml index 9b4944a..2f6fa89 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -# Copyright 2016 Peter Dimov +# Copyright 2016, 2017 Peter Dimov # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) @@ -10,10 +10,27 @@ branches: only: - master - develop + - /feature\/.*/ + + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-9.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-10.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-11.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-12.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + TOOLSET: msvc-14.0 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + TOOLSET: msvc-14.1 install: + - set BOOST_BRANCH=develop + - if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master - cd .. - - git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost-root + - git clone -b %BOOST_BRANCH% https://github.com/boostorg/boost.git boost-root - cd boost-root - git submodule init libs/align - git submodule init libs/assert @@ -38,4 +55,4 @@ install: build: off test_script: - - b2 libs/smart_ptr/test toolset=msvc-9.0,msvc-10.0,msvc-11.0,msvc-14.0 + - b2 libs/system/test toolset=%TOOLSET% From fff61ab5d6e9c0435917599897a5ae680cf3ace5 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 03:35:12 +0300 Subject: [PATCH 4/8] Add clang 3.5 to ravis --- .travis.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.travis.yml b/.travis.yml index f7ff0dc..58e0268 100644 --- a/.travis.yml +++ b/.travis.yml @@ -196,6 +196,28 @@ matrix: - os: linux env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11 + - os: linux + compiler: clang++-3.5 + env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.5 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.5 + + - os: linux + compiler: clang++-3.5 + env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.5 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.5 + - os: linux env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++03 addons: From 49095c3236f698466ab821ec824e9e215e83153e Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 03:36:49 +0300 Subject: [PATCH 5/8] Fix appveyor.yml --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 2f6fa89..5442fe5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,6 +12,7 @@ branches: - develop - /feature\/.*/ +environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 TOOLSET: msvc-9.0 From 9c18322e85e72f2276b943bd307199dcdc054f68 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 03:55:48 +0300 Subject: [PATCH 6/8] Fix appveyor.yml again --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 5442fe5..dad83bc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -56,4 +56,4 @@ install: build: off test_script: - - b2 libs/system/test toolset=%TOOLSET% + - b2 libs/smart_ptr/test toolset=%TOOLSET% From 4341446e042af92ee08275f12f7412171d4b5da3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 04:21:22 +0300 Subject: [PATCH 7/8] #ifdef constexpr tests on msvc and clang c++11 --- test/sp_constexpr_test.cpp | 16 ++++++++++++++++ test/sp_constexpr_test2.cpp | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/test/sp_constexpr_test.cpp b/test/sp_constexpr_test.cpp index 1d345ea..20f8c85 100644 --- a/test/sp_constexpr_test.cpp +++ b/test/sp_constexpr_test.cpp @@ -9,8 +9,24 @@ // #include +#include + +#define HAVE_CONSTEXPR_INIT #if defined( BOOST_NO_CXX11_CONSTEXPR ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR ) +// Clang 4+ in C++11 mode works too, but how to detect it? +# undef HAVE_CONSTEXPR_INIT +#endif + +#if !defined( HAVE_CONSTEXPR_INIT ) int main() { diff --git a/test/sp_constexpr_test2.cpp b/test/sp_constexpr_test2.cpp index 4e5cf37..238c8f4 100644 --- a/test/sp_constexpr_test2.cpp +++ b/test/sp_constexpr_test2.cpp @@ -9,8 +9,24 @@ // #include +#include + +#define HAVE_CONSTEXPR_INIT #if defined( BOOST_NO_CXX11_CONSTEXPR ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) +# undef HAVE_CONSTEXPR_INIT +#endif + +#if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR ) +// Clang 4+ in C++11 mode works too, but how to detect it? +# undef HAVE_CONSTEXPR_INIT +#endif + +#if !defined( HAVE_CONSTEXPR_INIT ) int main() { From 79e6fcdd61c275a8a135930ea776ba68656fa297 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2017 05:00:42 +0300 Subject: [PATCH 8/8] Remove comment; C++11 does not guarantee this static init --- test/sp_constexpr_test.cpp | 1 - test/sp_constexpr_test2.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/test/sp_constexpr_test.cpp b/test/sp_constexpr_test.cpp index 20f8c85..7238e26 100644 --- a/test/sp_constexpr_test.cpp +++ b/test/sp_constexpr_test.cpp @@ -22,7 +22,6 @@ #endif #if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR ) -// Clang 4+ in C++11 mode works too, but how to detect it? # undef HAVE_CONSTEXPR_INIT #endif diff --git a/test/sp_constexpr_test2.cpp b/test/sp_constexpr_test2.cpp index 238c8f4..e508fa1 100644 --- a/test/sp_constexpr_test2.cpp +++ b/test/sp_constexpr_test2.cpp @@ -22,7 +22,6 @@ #endif #if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR ) -// Clang 4+ in C++11 mode works too, but how to detect it? # undef HAVE_CONSTEXPR_INIT #endif