mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Fix addressof for nullptr_t values. Fixes #5487.
This commit is contained in:
parent
d595357b41
commit
50eafe2027
50
addressof_np_test.cpp
Normal file
50
addressof_np_test.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Copyright 2013 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 <boost/utility/addressof.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
#if defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
void nullptr_test()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void nullptr_test()
|
||||
{
|
||||
{
|
||||
auto x = nullptr;
|
||||
BOOST_TEST( boost::addressof(x) == &x );
|
||||
}
|
||||
|
||||
{
|
||||
auto const x = nullptr;
|
||||
BOOST_TEST( boost::addressof(x) == &x );
|
||||
}
|
||||
|
||||
{
|
||||
auto volatile x = nullptr;
|
||||
BOOST_TEST( boost::addressof(x) == &x );
|
||||
}
|
||||
|
||||
{
|
||||
auto const volatile x = nullptr;
|
||||
BOOST_TEST( boost::addressof(x) == &x );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
nullptr_test();
|
||||
return boost::report_errors();
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2002 Brad King (brad.king@kitware.com)
|
||||
// Douglas Gregor (gregod@cs.rpi.edu)
|
||||
//
|
||||
// Copyright (C) 2002, 2008 Peter Dimov
|
||||
// Copyright (C) 2002, 2008, 2013 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -14,6 +14,7 @@
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -46,6 +47,60 @@ template<class T> struct addressof_impl
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
#if defined( __clang__ ) && !defined( _LIBCPP_VERSION ) && !defined( BOOST_NO_CXX11_DECLTYPE )
|
||||
|
||||
typedef decltype(nullptr) addr_nullptr_t;
|
||||
|
||||
#else
|
||||
|
||||
typedef std::nullptr_t addr_nullptr_t;
|
||||
|
||||
#endif
|
||||
|
||||
template<> struct addressof_impl< addr_nullptr_t >
|
||||
{
|
||||
typedef addr_nullptr_t T;
|
||||
|
||||
static BOOST_FORCEINLINE T * f( T & v, int )
|
||||
{
|
||||
return &v;
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct addressof_impl< addr_nullptr_t const >
|
||||
{
|
||||
typedef addr_nullptr_t const T;
|
||||
|
||||
static BOOST_FORCEINLINE T * f( T & v, int )
|
||||
{
|
||||
return &v;
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct addressof_impl< addr_nullptr_t volatile >
|
||||
{
|
||||
typedef addr_nullptr_t volatile T;
|
||||
|
||||
static BOOST_FORCEINLINE T * f( T & v, int )
|
||||
{
|
||||
return &v;
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct addressof_impl< addr_nullptr_t const volatile >
|
||||
{
|
||||
typedef addr_nullptr_t const volatile T;
|
||||
|
||||
static BOOST_FORCEINLINE T * f( T & v, int )
|
||||
{
|
||||
return &v;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class T>
|
||||
|
@ -17,6 +17,7 @@ alias unit_test_framework
|
||||
test-suite utility
|
||||
:
|
||||
[ run ../addressof_fn_test.cpp ]
|
||||
[ run ../addressof_np_test.cpp ]
|
||||
[ run ../addressof_test.cpp ]
|
||||
[ run ../addressof_test2.cpp ]
|
||||
[ run ../assert_test.cpp ]
|
||||
|
Loading…
x
Reference in New Issue
Block a user