From 9875cfdc9821c44a5e9e49753d2bee34c8d7b299 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 25 Mar 2019 16:17:06 +0200 Subject: [PATCH 1/4] Add variant_npos and valueless_by_exception() --- include/boost/variant2/variant.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 3cf2dc1..c109632 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -1,7 +1,7 @@ #ifndef BOOST_VARIANT2_VARIANT_HPP_INCLUDED #define BOOST_VARIANT2_VARIANT_HPP_INCLUDED -// Copyright 2017, 2018 Peter Dimov. +// Copyright 2017-2019 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -266,6 +266,10 @@ template struct variant_alternative> #endif +// variant_npos + +constexpr std::size_t variant_npos = -1; + // holds_alternative template constexpr bool holds_alternative( variant const& v ) noexcept @@ -1350,6 +1354,11 @@ public: // value status + constexpr bool valueless_by_exception() const noexcept + { + return false; + } + using variant_base::index; // swap From f1b1e7cade6c62268a62b3d9e95dcfa56618ddab Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 25 Mar 2019 17:40:20 +0200 Subject: [PATCH 2/4] Enable warnings-as-errors in test/Jamfile --- test/Jamfile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/Jamfile b/test/Jamfile index 7ad76a4..18642a0 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -1,6 +1,6 @@ # Boost.Variant2 Library Test Jamfile # -# Copyright 2015-2017 Peter Dimov +# Copyright 2015-2019 Peter Dimov # # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at @@ -9,7 +9,19 @@ import testing ; import ../../config/checks/config : requires ; -project : requirements [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr ] ; +project + : default-build + + all + + : requirements + + [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr ] + + msvc:on + gcc:on + clang:on + ; run variant_size.cpp ; run variant_alternative.cpp ; From 3808c9b122ace26b04a31c68c88e3869812963bf Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 25 Mar 2019 17:40:39 +0200 Subject: [PATCH 3/4] Fix variant_npos warning --- include/boost/variant2/variant.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index c109632..5515600 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -268,7 +268,7 @@ template struct variant_alternative> // variant_npos -constexpr std::size_t variant_npos = -1; +constexpr std::size_t variant_npos = ~static_cast( 0 ); // holds_alternative From 1da38922395c1a0cbb7be4419c6abdbc296bd726 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 25 Mar 2019 19:50:33 +0200 Subject: [PATCH 4/4] Disable C4702 (unreachable code) for the throwing tests --- test/variant_convert_construct_throw.cpp | 4 ++++ test/variant_copy_assign_throw.cpp | 4 ++++ test/variant_copy_construct_throw.cpp | 4 ++++ test/variant_move_assign_throw.cpp | 4 ++++ test/variant_move_construct_throw.cpp | 4 ++++ test/variant_subset.cpp | 4 ++++ test/variant_valueless.cpp | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/test/variant_convert_construct_throw.cpp b/test/variant_convert_construct_throw.cpp index 79757fc..bb53d7c 100644 --- a/test/variant_convert_construct_throw.cpp +++ b/test/variant_convert_construct_throw.cpp @@ -6,6 +6,10 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4702 ) // unreachable code +#endif + #include #include #include diff --git a/test/variant_copy_assign_throw.cpp b/test/variant_copy_assign_throw.cpp index 7f98f70..a13dccb 100644 --- a/test/variant_copy_assign_throw.cpp +++ b/test/variant_copy_assign_throw.cpp @@ -6,6 +6,10 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4702 ) // unreachable code +#endif + #include #include #include diff --git a/test/variant_copy_construct_throw.cpp b/test/variant_copy_construct_throw.cpp index 88937c2..81b44d9 100644 --- a/test/variant_copy_construct_throw.cpp +++ b/test/variant_copy_construct_throw.cpp @@ -6,6 +6,10 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4702 ) // unreachable code +#endif + #include #include #include diff --git a/test/variant_move_assign_throw.cpp b/test/variant_move_assign_throw.cpp index 6e65518..c1df594 100644 --- a/test/variant_move_assign_throw.cpp +++ b/test/variant_move_assign_throw.cpp @@ -6,6 +6,10 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4702 ) // unreachable code +#endif + #include #include #include diff --git a/test/variant_move_construct_throw.cpp b/test/variant_move_construct_throw.cpp index 01b2b02..aabf7d2 100644 --- a/test/variant_move_construct_throw.cpp +++ b/test/variant_move_construct_throw.cpp @@ -6,6 +6,10 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4702 ) // unreachable code +#endif + #include #include #include diff --git a/test/variant_subset.cpp b/test/variant_subset.cpp index 86cd505..90c9bc2 100644 --- a/test/variant_subset.cpp +++ b/test/variant_subset.cpp @@ -6,6 +6,10 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4702 ) // unreachable code +#endif + #include #include #include diff --git a/test/variant_valueless.cpp b/test/variant_valueless.cpp index 6a13086..176c674 100644 --- a/test/variant_valueless.cpp +++ b/test/variant_valueless.cpp @@ -6,6 +6,10 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4702 ) // unreachable code +#endif + #include #include #include