From b832d4c54f04756e2d966dd6a6b0986c9a69ed98 Mon Sep 17 00:00:00 2001 From: petamas Date: Wed, 3 Jan 2018 10:37:37 +0100 Subject: [PATCH 1/5] Add test for template parameter with member enum T (fails by default on VS2015) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://github.com/boostorg/optional/issues/46ű --- test/Jamfile.v2 | 1 + test/optional_test_member_T.cpp | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/optional_test_member_T.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 129dd49..edc2e14 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -43,6 +43,7 @@ import testing ; [ run optional_test_emplace.cpp ] [ run optional_test_minimum_requirements.cpp ] [ run optional_test_msvc_bug_workaround.cpp ] + [ run optional_test_member_T.cpp ] [ run optional_test_tc_base.cpp ] [ compile optional_test_sfinae_friendly_ctor.cpp ] [ compile-fail optional_test_ref_convert_assign_const_int_prevented.cpp ] diff --git a/test/optional_test_member_T.cpp b/test/optional_test_member_T.cpp new file mode 100644 index 0000000..325838d --- /dev/null +++ b/test/optional_test_member_T.cpp @@ -0,0 +1,44 @@ +// Copyright (C) 2014 Andrzej Krzemienski. +// +// Use, modification, and distribution is subject to 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 http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: +// akrzemi1@gmail.com + +#include "boost/optional/optional.hpp" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#include "boost/core/lightweight_test.hpp" + +struct Status +{ + enum T + { + DISCONNECTED, + CONNECTING, + CONNECTED, + }; + + T mValue; +}; + +void test_member_T() +{ + boost::optional x = Status(); + x->mValue = Status::CONNECTED; + + BOOST_TEST(x->mValue == Status::CONNECTED); +} + +int main() +{ + test_member_T(); + return boost::report_errors(); +} From e230bd83c6623dfee372b3e370c69072794a36f2 Mon Sep 17 00:00:00 2001 From: petamas Date: Wed, 3 Jan 2018 10:46:31 +0100 Subject: [PATCH 2/5] Fix compilation of template parameter with member enum T on VS2015 Issue: https://github.com/boostorg/optional/issues/46 --- include/boost/optional/optional.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index c0f10e1..715adb9 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -747,7 +747,7 @@ class optional_base : public optional_tag private : -#if BOOST_WORKAROUND(BOOST_MSVC, <= 1600) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1900)) void destroy_impl ( ) { m_storage.ptr_ref()->~T() ; m_initialized = false ; } #else void destroy_impl ( ) { m_storage.ref().T::~T() ; m_initialized = false ; } From a5aaf4d8d0f2f7ab5a65fcb0af730460e55bffe7 Mon Sep 17 00:00:00 2001 From: Peter Klotz Date: Sun, 11 Feb 2018 21:03:54 +0100 Subject: [PATCH 3/5] Fixed recurring typo --- include/boost/optional/detail/old_optional_implementation.hpp | 2 +- include/boost/optional/optional.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/optional/detail/old_optional_implementation.hpp b/include/boost/optional/detail/old_optional_implementation.hpp index 4e888ed..16dee20 100644 --- a/include/boost/optional/detail/old_optional_implementation.hpp +++ b/include/boost/optional/detail/old_optional_implementation.hpp @@ -147,7 +147,7 @@ class optional_base : public optional_tag } #endif - // Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialzed optional. + // Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional. // Can throw if T::T(T const&) does optional_base ( bool cond, argument_type val ) : diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 715adb9..ecf686e 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -149,7 +149,7 @@ class optional_base : public optional_tag } #endif - // Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialzed optional. + // Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional. // Can throw if T::T(T const&) does optional_base ( bool cond, argument_type val ) : @@ -160,7 +160,7 @@ class optional_base : public optional_tag } #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES - // Creates an optional initialized with 'move(val)' IFF cond is true, otherwise creates an uninitialzed optional. + // Creates an optional initialized with 'move(val)' IFF cond is true, otherwise creates an uninitialized optional. // Can throw if T::T(T &&) does optional_base ( bool cond, rval_reference_type val ) : From 76ff82d1912901f188599acea09cdcdb232353bd Mon Sep 17 00:00:00 2001 From: akrzemi1 Date: Thu, 15 Feb 2018 22:51:08 +0100 Subject: [PATCH 4/5] Silenced warning -Wzero-as-null-pointer-constant --- .../detail/old_optional_implementation.hpp | 2 +- .../detail/optional_reference_spec.hpp | 30 +++++++++---------- include/boost/optional/optional.hpp | 6 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/boost/optional/detail/old_optional_implementation.hpp b/include/boost/optional/detail/old_optional_implementation.hpp index 16dee20..62c31ee 100644 --- a/include/boost/optional/detail/old_optional_implementation.hpp +++ b/include/boost/optional/detail/old_optional_implementation.hpp @@ -730,7 +730,7 @@ class optional : public optional_detail::optional_base explicit optional ( Expr&& expr, BOOST_DEDUCED_TYPENAME boost::disable_if_c< (boost::is_base_of::type>::value) || - boost::is_same::type, none_t>::value >::type* = 0 + boost::is_same::type, none_t>::value, bool >::type = true ) : base(boost::forward(expr),boost::addressof(expr)) {optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref();} diff --git a/include/boost/optional/detail/optional_reference_spec.hpp b/include/boost/optional/detail/optional_reference_spec.hpp index ce55875..012e91a 100644 --- a/include/boost/optional/detail/optional_reference_spec.hpp +++ b/include/boost/optional/detail/optional_reference_spec.hpp @@ -132,11 +132,11 @@ public: // the following two implement a 'conditionally explicit' constructor: condition is a hack for buggy compilers with srewed conversion construction from const int template - explicit optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && detail::is_const_integral_bad_for_conversion::value>::type* = 0) BOOST_NOEXCEPT + explicit optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && detail::is_const_integral_bad_for_conversion::value, bool>::type = true) BOOST_NOEXCEPT : ptr_(boost::addressof(rhs)) {} template - optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && !detail::is_const_integral_bad_for_conversion::value>::type* = 0) BOOST_NOEXCEPT + optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && !detail::is_const_integral_bad_for_conversion::value, bool>::type = true) BOOST_NOEXCEPT : ptr_(boost::addressof(rhs)) {} optional& operator=(const optional& rhs) BOOST_NOEXCEPT { ptr_ = rhs.get_ptr(); return *this; } @@ -165,11 +165,11 @@ public: optional(T&& /* rhs */) BOOST_NOEXCEPT { detail::prevent_binding_rvalue(); } template - optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) BOOST_NOEXCEPT : ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue(); } template - optional(bool cond, R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + optional(bool cond, R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(r) : 0) { detail::prevent_binding_rvalue(); } template @@ -177,19 +177,19 @@ public: operator=(R&& r) BOOST_NOEXCEPT { detail::prevent_binding_rvalue(); ptr_ = boost::addressof(r); return *this; } template - void emplace(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + void emplace(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) BOOST_NOEXCEPT { detail::prevent_binding_rvalue(); ptr_ = boost::addressof(r); } template - T& get_value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) const BOOST_NOEXCEPT + T& get_value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) const BOOST_NOEXCEPT { detail::prevent_binding_rvalue(); return ptr_ ? *ptr_ : r; } template - T& value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) const BOOST_NOEXCEPT + T& value_or(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) const BOOST_NOEXCEPT { detail::prevent_binding_rvalue(); return ptr_ ? *ptr_ : r; } template - void reset(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + void reset(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) BOOST_NOEXCEPT { detail::prevent_binding_rvalue(); ptr_ = boost::addressof(r); } template @@ -200,15 +200,15 @@ public: // the following two implement a 'conditionally explicit' constructor template - explicit optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && detail::is_const_integral_bad_for_conversion::value >::type* = 0) BOOST_NOEXCEPT + explicit optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && detail::is_const_integral_bad_for_conversion::value, bool>::type = true) BOOST_NOEXCEPT : ptr_(boost::addressof(v)) { } template - optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && !detail::is_const_integral_bad_for_conversion::value >::type* = 0) BOOST_NOEXCEPT + optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c::value && !detail::is_const_integral_bad_for_conversion::value, bool>::type = true) BOOST_NOEXCEPT : ptr_(boost::addressof(v)) { } template - optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {} + optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {} template BOOST_DEDUCED_TYPENAME boost::enable_if, optional&>::type @@ -219,19 +219,19 @@ public: } template - void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); } template - T& get_value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) const BOOST_NOEXCEPT + T& get_value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) const BOOST_NOEXCEPT { return ptr_ ? *ptr_ : v; } template - T& value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) const BOOST_NOEXCEPT + T& value_or(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) const BOOST_NOEXCEPT { return ptr_ ? *ptr_ : v; } template - void reset(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if >::type* = 0) BOOST_NOEXCEPT + void reset(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if, bool>::type = true) BOOST_NOEXCEPT { ptr_ = boost::addressof(v); } template diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index ecf686e..74ef49c 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -884,7 +884,7 @@ class optional template explicit optional ( optional const& rhs #ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS - ,typename boost::enable_if< optional_detail::is_optional_constructible >::type* = 0 + ,BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_constructible, bool>::type = true #endif ) : @@ -901,7 +901,7 @@ class optional template explicit optional ( optional && rhs #ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS - ,typename boost::enable_if< optional_detail::is_optional_constructible >::type* = 0 + ,BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_constructible, bool>::type = true #endif ) : @@ -927,7 +927,7 @@ class optional template explicit optional ( Expr&& expr, - BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_val_init_candidate >::type* = 0 + BOOST_DEDUCED_TYPENAME boost::enable_if< optional_detail::is_optional_val_init_candidate, bool>::type = true ) : base(boost::forward(expr),boost::addressof(expr)) {} From 33c7a6aa2b418c15254e2703c63df36ea843af5e Mon Sep 17 00:00:00 2001 From: akrzemi1 Date: Thu, 1 Mar 2018 01:10:42 +0100 Subject: [PATCH 5/5] docs: relnotes for 1.67 --- doc/91_relnotes.qbk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/91_relnotes.qbk b/doc/91_relnotes.qbk index 228760d..d34861b 100644 --- a/doc/91_relnotes.qbk +++ b/doc/91_relnotes.qbk @@ -11,6 +11,12 @@ [section:relnotes Release Notes] +[heading Boost Release 1.67] + +* Fixed [@https://github.com/boostorg/optional/issues/46 issue #46]. +* Fixed `-Wzero-as-null-pointer-constant` warnings. + + [heading Boost Release 1.66] * On newer compilers `optional` is now trivially-copyable for scalar `T`s. This uses a different storage (just `T` rather than `aligned_storage`). We require the compiler to support defaulted functions.