Skip to content

Commit

Permalink
Merge pull request #77 from BartSiwek/fix_zero_as_null_pointer_constant
Browse files Browse the repository at this point in the history
Fix GCC zero-as-null-pointer-constat warnings
  • Loading branch information
apolukhin committed Apr 3, 2020
2 parents bee77d4 + 74a9d76 commit 1ba33a5
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 53 deletions.
18 changes: 10 additions & 8 deletions include/boost/variant/detail/apply_visitor_binary.hpp
Expand Up @@ -261,13 +261,13 @@ class apply_visitor_binary_invoke_cpp14
public: // visitor interfaces

template <typename Value2>
decltype(auto) operator()(Value2&& value2, typename enable_if_c<MoveSemantics && is_same<Value2, Value2>::value>::type* = 0)
decltype(auto) operator()(Value2&& value2, typename enable_if_c<MoveSemantics && is_same<Value2, Value2>::value, bool>::type = true)
{
return visitor_(::boost::move(value1_), ::boost::forward<Value2>(value2));
}

template <typename Value2>
decltype(auto) operator()(Value2&& value2, typename disable_if_c<MoveSemantics && is_same<Value2, Value2>::value>::type* = 0)
decltype(auto) operator()(Value2&& value2, typename disable_if_c<MoveSemantics && is_same<Value2, Value2>::value, bool>::type = true)
{
return visitor_(value1_, ::boost::forward<Value2>(value2));
}
Expand All @@ -293,7 +293,7 @@ class apply_visitor_binary_unwrap_cpp14
public: // visitor interfaces

template <typename Value1>
decltype(auto) operator()(Value1&& value1, typename enable_if_c<MoveSemantics && is_same<Value1, Value1>::value>::type* = 0)
decltype(auto) operator()(Value1&& value1, typename enable_if_c<MoveSemantics && is_same<Value1, Value1>::value, bool>::type = true)
{
apply_visitor_binary_invoke_cpp14<
Visitor
Expand All @@ -305,7 +305,7 @@ class apply_visitor_binary_unwrap_cpp14
}

template <typename Value1>
decltype(auto) operator()(Value1&& value1, typename disable_if_c<MoveSemantics && is_same<Value1, Value1>::value>::type* = 0)
decltype(auto) operator()(Value1&& value1, typename disable_if_c<MoveSemantics && is_same<Value1, Value1>::value, bool>::type = true)
{
apply_visitor_binary_invoke_cpp14<
Visitor
Expand All @@ -325,8 +325,9 @@ class apply_visitor_binary_unwrap_cpp14
template <typename Visitor, typename Visitable1, typename Visitable2>
inline decltype(auto) apply_visitor(Visitor& visitor, Visitable1&& visitable1, Visitable2&& visitable2,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>
>::type* = 0)
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
::boost::detail::variant::apply_visitor_binary_unwrap_cpp14<
Visitor, Visitable2, ! ::boost::is_lvalue_reference<Visitable2>::value
Expand All @@ -338,8 +339,9 @@ inline decltype(auto) apply_visitor(Visitor& visitor, Visitable1&& visitable1, V
template <typename Visitor, typename Visitable1, typename Visitable2>
inline decltype(auto) apply_visitor(const Visitor& visitor, Visitable1&& visitable1, Visitable2&& visitable2,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>
>::type* = 0)
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
::boost::detail::variant::apply_visitor_binary_unwrap_cpp14<
const Visitor, Visitable2, ! ::boost::is_lvalue_reference<Visitable2>::value
Expand Down
5 changes: 3 additions & 2 deletions include/boost/variant/detail/apply_visitor_unary.hpp
Expand Up @@ -130,8 +130,9 @@ struct result_wrapper1
template <typename Visitor, typename Visitable>
inline decltype(auto) apply_visitor(Visitor&& visitor, Visitable&& visitable,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>
>::type* = 0)
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
boost::detail::variant::result_wrapper1<Visitor, Visitable> cpp14_vis(::boost::forward<Visitor>(visitor));
return ::boost::forward<Visitable>(visitable).apply_visitor(cpp14_vis);
Expand Down
14 changes: 8 additions & 6 deletions include/boost/variant/detail/multivisitors_cpp14_based.hpp
Expand Up @@ -19,7 +19,7 @@

#include <boost/variant/detail/multivisitors_cpp14_based.hpp>

namespace boost {
namespace boost {

namespace detail { namespace variant {

Expand Down Expand Up @@ -106,8 +106,9 @@ namespace detail { namespace variant {
template <class Visitor, class T1, class T2, class T3, class... TN>
inline decltype(auto) apply_visitor(const Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>
>::type* = 0)
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
return boost::apply_visitor(
::boost::detail::variant::make_one_by_one_visitor_and_value_referer_cpp14(
Expand All @@ -122,13 +123,14 @@ namespace detail { namespace variant {
::boost::forward<T1>(v1)
);
}


template <class Visitor, class T1, class T2, class T3, class... TN>
inline decltype(auto) apply_visitor(Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn,
typename boost::disable_if<
boost::detail::variant::has_result_type<Visitor>
>::type* = 0)
boost::detail::variant::has_result_type<Visitor>,
bool
>::type = true)
{
return ::boost::apply_visitor(
::boost::detail::variant::make_one_by_one_visitor_and_value_referer_cpp14(
Expand Down
23 changes: 15 additions & 8 deletions include/boost/variant/detail/visitation_impl.hpp
Expand Up @@ -34,9 +34,9 @@
#include <boost/type_traits/has_nothrow_copy.hpp>
#include <boost/type_traits/is_nothrow_move_constructible.hpp>

#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning (push)
# pragma warning (disable : 4702) //unreachable code
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning (push)
# pragma warning (disable : 4702) //unreachable code
#endif

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -58,6 +58,13 @@

#endif

// Define a compiler generic null pointer value
#if defined(BOOST_NO_NULLPTR)
#define BOOST_VARIANT_NULL 0
#else
#define BOOST_VARIANT_NULL nullptr
#endif

namespace boost {
namespace detail { namespace variant {

Expand Down Expand Up @@ -177,7 +184,7 @@ inline typename Visitor::result_type
visitation_impl(
int, int, Visitor&, VPCV
, mpl::true_ // is_apply_visitor_unrolled
, NBF, W* = 0, S* = 0
, NBF, W* = BOOST_VARIANT_NULL, S* = BOOST_VARIANT_NULL
)
{
// should never be here at runtime!
Expand All @@ -196,7 +203,7 @@ visitation_impl(
, Visitor& visitor, VoidPtrCV storage
, mpl::false_ // is_apply_visitor_unrolled
, NoBackupFlag no_backup_flag
, Which* = 0, step0* = 0
, Which* = BOOST_VARIANT_NULL, step0* = BOOST_VARIANT_NULL
)
{
// Typedef apply_visitor_unrolled steps and associated types...
Expand Down Expand Up @@ -263,8 +270,8 @@ visitation_impl(
}} // namespace detail::variant
} // namespace boost

#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(pop)
#endif
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(pop)
#endif

#endif // BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP
9 changes: 7 additions & 2 deletions include/boost/variant/get.hpp
Expand Up @@ -102,8 +102,13 @@ struct get_visitor
# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)
# else
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = 0
# if defined(BOOST_NO_NULLPTR)
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = 0
# else
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = nullptr
# endif
# endif
#endif

Expand Down
9 changes: 7 additions & 2 deletions include/boost/variant/polymorphic_get.hpp
Expand Up @@ -135,8 +135,13 @@ struct get_polymorphic_visitor
# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)
# else
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = 0
# if defined(BOOST_NO_NULLPTR)
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = 0
# else
# define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t) \
, t* = nullptr
# endif
# endif
#endif

Expand Down
49 changes: 26 additions & 23 deletions include/boost/variant/variant.hpp
Expand Up @@ -130,7 +130,7 @@ struct max_value

typedef typename mpl::transform1<Sequence, F>::type transformed_;
typedef typename mpl::max_element<transformed_

>::type max_it;

public: // metafunction result
Expand Down Expand Up @@ -1372,15 +1372,15 @@ class variant
destroy_content();
}

variant()
variant()
#if !(defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5130))
BOOST_NOEXCEPT_IF(boost::has_nothrow_constructor<internal_T0>::value)
#endif
{
#ifdef _MSC_VER
#pragma warning( push )
// behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
#pragma warning( disable : 4345 )
// behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
#pragma warning( disable : 4345 )
#endif
// NOTE TO USER :
// Compile error from here indicates that the first bound
Expand Down Expand Up @@ -1416,7 +1416,7 @@ class variant
int internal_visit(T& operand, int) const
{
// NOTE TO USER :
// Compile error here indicates one of the source variant's types
// Compile error here indicates one of the source variant's types
// cannot be unambiguously converted to the destination variant's
// types (or that no conversion exists).
//
Expand Down Expand Up @@ -1492,7 +1492,7 @@ class variant
int internal_visit(T& operand, int) const
{
// NOTE TO USER :
// Compile error here indicates one of the source variant's types
// Compile error here indicates one of the source variant's types
// cannot be unambiguously converted to the destination variant's
// types (or that no conversion exists).
//
Expand Down Expand Up @@ -1539,7 +1539,7 @@ class variant
friend class convert_move_into;
#endif

private: // helpers, for structors, below
private: // helpers, for structors, below

template <typename T>
void convert_construct(
Expand All @@ -1549,7 +1549,7 @@ class variant
)
{
// NOTE TO USER :
// Compile error here indicates that the given type is not
// Compile error here indicates that the given type is not
// unambiguously convertible to one of the variant's types
// (or that no conversion exists).
//
Expand All @@ -1570,7 +1570,7 @@ class variant
)
{
// NOTE TO USER :
// Compile error here indicates that the given type is not
// Compile error here indicates that the given type is not
// unambiguously convertible to one of the variant's types
// (or that no conversion exists).
//
Expand Down Expand Up @@ -1688,7 +1688,7 @@ class variant
, long
)
{
convert_construct_variant(operand);
convert_construct_variant(operand);
}

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
Expand All @@ -1701,7 +1701,7 @@ class variant
, long
)
{
convert_construct_variant( detail::variant::move(operand) );
convert_construct_variant( detail::variant::move(operand) );
}
#endif

Expand All @@ -1713,8 +1713,9 @@ class variant
mpl::and_<
mpl::not_< boost::is_same<T, variant> >,
boost::detail::variant::is_variant_constructible_from<const T&, internal_types>
>,
boost::is_same<T, boost::recursive_variant_> > >::type* = 0)
>,
boost::is_same<T, boost::recursive_variant_> >,
bool >::type = true)
{
convert_construct(operand, 1L);
}
Expand All @@ -1728,7 +1729,8 @@ class variant
mpl::not_< boost::is_same<T, variant> >,
boost::detail::variant::is_variant_constructible_from<T&, internal_types>
>,
boost::is_same<T, boost::recursive_variant_> > >::type* = 0
boost::is_same<T, boost::recursive_variant_> >,
bool >::type = true
)
{
convert_construct(operand, 1L);
Expand All @@ -1744,7 +1746,8 @@ class variant
mpl::not_< boost::is_same<T, variant> >,
boost::detail::variant::is_variant_constructible_from<T&&, internal_types>
>,
boost::is_same<T, boost::recursive_variant_> > >::type* = 0)
boost::is_same<T, boost::recursive_variant_> >,
bool >::type = true)
{
convert_construct( detail::variant::move(operand), 1L);
}
Expand Down Expand Up @@ -1927,9 +1930,9 @@ class variant
assigner& operator= (assigner const&);
#endif
};

friend class assigner;

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
// class move_assigner
//
Expand All @@ -1948,7 +1951,7 @@ class variant
}

private: // helpers, for internal visitor interface (below)

template <typename RhsT, typename B2>
void assign_impl(
RhsT& rhs_content
Expand Down Expand Up @@ -2008,7 +2011,7 @@ class variant
// In the event of success, indicate new content type:
assigner::lhs_.indicate_which(assigner::rhs_which_); // nothrow
}

template <typename RhsT>
void assign_impl(
RhsT& rhs_content
Expand Down Expand Up @@ -2063,7 +2066,7 @@ class variant
{
// Otherwise, perform general (copy-based) variant assignment:
assigner visitor(*this, rhs.which());
rhs.internal_apply_visitor(visitor);
rhs.internal_apply_visitor(visitor);
}
}

Expand All @@ -2081,7 +2084,7 @@ class variant
{
// Otherwise, perform general (move-based) variant assignment:
move_assigner visitor(*this, rhs.which());
rhs.internal_apply_visitor(visitor);
rhs.internal_apply_visitor(visitor);
}
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
Expand Down Expand Up @@ -2137,7 +2140,7 @@ class variant
boost::detail::variant::is_variant_constructible_from<T&&, internal_types>
>,
variant&
>::type operator=(T&& rhs)
>::type operator=(T&& rhs)
{
move_assign( detail::variant::move(rhs) );
return *this;
Expand Down Expand Up @@ -2165,7 +2168,7 @@ class variant
}

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
variant& operator=(variant&& rhs)
variant& operator=(variant&& rhs)
#if !defined(__GNUC__) || (__GNUC__ != 4) || (__GNUC_MINOR__ > 6) || defined(__clang__)
BOOST_NOEXCEPT_IF(variant_move_noexcept_constructible::type::value && variant_move_noexcept_assignable::type::value)
#endif
Expand Down

0 comments on commit 1ba33a5

Please sign in to comment.