From dc6003e26f97c574affcdde0620d2ab966963244 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sat, 22 Apr 2017 23:50:00 -0400 Subject: [PATCH] Disable addressof for r-values when possible --- include/boost/core/addressof.hpp | 10 ++++++++++ test/Jamfile.v2 | 1 + test/addressof_constexpr_test.cpp | 7 +++---- test/addressof_fail_rvalue.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 test/addressof_fail_rvalue.cpp diff --git a/include/boost/core/addressof.hpp b/include/boost/core/addressof.hpp index 0a2b46b..efde98a 100644 --- a/include/boost/core/addressof.hpp +++ b/include/boost/core/addressof.hpp @@ -262,4 +262,14 @@ addressof(T& o) BOOST_NOEXCEPT } /* boost */ #endif +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) +namespace boost { + +template +const T* addressof(const T&&) = delete; + +} /* boost */ +#endif + #endif diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 72e62a2..fded1cd 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -14,6 +14,7 @@ run addressof_test2.cpp ; run addressof_np_test.cpp ; run addressof_fn_test.cpp ; compile addressof_constexpr_test.cpp ; +compile-fail addressof_fail_rvalue.cpp ; run checked_delete_test.cpp ; compile-fail checked_delete_fail.cpp ; diff --git a/test/addressof_constexpr_test.cpp b/test/addressof_constexpr_test.cpp index 9d93565..d7255a9 100644 --- a/test/addressof_constexpr_test.cpp +++ b/test/addressof_constexpr_test.cpp @@ -1,10 +1,9 @@ /* Copyright 2017 Glen Joseph Fernandes - +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include diff --git a/test/addressof_fail_rvalue.cpp b/test/addressof_fail_rvalue.cpp new file mode 100644 index 0000000..258eaaa --- /dev/null +++ b/test/addressof_fail_rvalue.cpp @@ -0,0 +1,26 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ + +#include + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) +struct type { }; + +inline const type function() +{ + return type(); +} + +int main() +{ + (void)boost::addressof(function()); +} +#else +#error Requires rvalue references and deleted functions +#endif