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. diff --git a/include/boost/optional/detail/old_optional_implementation.hpp b/include/boost/optional/detail/old_optional_implementation.hpp index 4e888ed..62c31ee 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 ) : @@ -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 c0f10e1..74ef49c 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 ) : @@ -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 ; } @@ -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)) {} 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(); +}