|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r51872 - in trunk: boost/utility libs/utility libs/utility/test
From: pdimov_at_[hidden]
Date: 2009-03-20 13:14:00
Author: pdimov
Date: 2009-03-20 13:14:00 EDT (Fri, 20 Mar 2009)
New Revision: 51872
URL: http://svn.boost.org/trac/boost/changeset/51872
Log:
Attempt to fix addressof in trunk to handle classes with conversion operators. Refs #2878.
Added:
trunk/libs/utility/addressof_fn_test.cpp (contents, props changed)
trunk/libs/utility/addressof_test2.cpp (contents, props changed)
Text files modified:
trunk/boost/utility/addressof.hpp | 16 ++++++++++++++++
trunk/libs/utility/test/Jamfile.v2 | 2 ++
2 files changed, 18 insertions(+), 0 deletions(-)
Modified: trunk/boost/utility/addressof.hpp
==============================================================================
--- trunk/boost/utility/addressof.hpp (original)
+++ trunk/boost/utility/addressof.hpp 2009-03-20 13:14:00 EDT (Fri, 20 Mar 2009)
@@ -21,6 +21,14 @@
namespace detail
{
+template<class T> struct addr_impl_ref
+{
+ T & v_;
+
+ inline addr_impl_ref( T & v ): v_( v ) {}
+ inline operator T& () const { return v_; }
+};
+
template<class T> struct addressof_impl
{
static inline T * f( T & v, long )
@@ -39,7 +47,15 @@
template<class T> T * addressof( T & v )
{
+#if BOOST_WORKAROUND( __BORLANDC__, < 0x560 )
+
return boost::detail::addressof_impl<T>::f( v, 0 );
+
+#else
+
+ return boost::detail::addressof_impl<T>::f( boost::detail::addr_impl_ref<T>( v ), 0 );
+
+#endif
}
// Borland doesn't like casting an array reference to a char reference
Added: trunk/libs/utility/addressof_fn_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/addressof_fn_test.cpp 2009-03-20 13:14:00 EDT (Fri, 20 Mar 2009)
@@ -0,0 +1,76 @@
+#include <boost/config.hpp>
+
+#if defined(BOOST_MSVC)
+#pragma warning(disable: 4786) // identifier truncated in debug info
+#pragma warning(disable: 4710) // function not inlined
+#pragma warning(disable: 4711) // function selected for automatic inline expansion
+#pragma warning(disable: 4514) // unreferenced inline removed
+#endif
+
+// addressof_fn_test.cpp: addressof( f )
+//
+// Copyright (c) 2008, 2009 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>
+
+
+void f0()
+{
+}
+
+void f1(int)
+{
+}
+
+void f2(int, int)
+{
+}
+
+void f3(int, int, int)
+{
+}
+
+void f4(int, int, int, int)
+{
+}
+
+void f5(int, int, int, int, int)
+{
+}
+
+void f6(int, int, int, int, int, int)
+{
+}
+
+void f7(int, int, int, int, int, int, int)
+{
+}
+
+void f8(int, int, int, int, int, int, int, int)
+{
+}
+
+void f9(int, int, int, int, int, int, int, int, int)
+{
+}
+
+int main()
+{
+ BOOST_TEST( boost::addressof( f0 ) == &f0 );
+ BOOST_TEST( boost::addressof( f1 ) == &f1 );
+ BOOST_TEST( boost::addressof( f2 ) == &f2 );
+ BOOST_TEST( boost::addressof( f3 ) == &f3 );
+ BOOST_TEST( boost::addressof( f4 ) == &f4 );
+ BOOST_TEST( boost::addressof( f5 ) == &f5 );
+ BOOST_TEST( boost::addressof( f6 ) == &f6 );
+ BOOST_TEST( boost::addressof( f7 ) == &f7 );
+ BOOST_TEST( boost::addressof( f8 ) == &f8 );
+ BOOST_TEST( boost::addressof( f9 ) == &f9 );
+
+ return boost::report_errors();
+}
Added: trunk/libs/utility/addressof_test2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/addressof_test2.cpp 2009-03-20 13:14:00 EDT (Fri, 20 Mar 2009)
@@ -0,0 +1,95 @@
+// Copyright (C) 2002 Brad King (brad.king_at_[hidden])
+// Douglas Gregor (gregod_at_[hidden])
+//
+// Copyright 2009 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)
+
+// For more information, see http://www.boost.org
+
+
+#include <boost/utility/addressof.hpp>
+
+#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
+#pragma warning(push, 3)
+#endif
+
+#include <iostream>
+
+#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
+#pragma warning(pop)
+#endif
+
+#include <boost/detail/lightweight_test.hpp>
+
+template<class T> void scalar_test( T * = 0 )
+{
+ T* px = new T();
+
+ T& x = *px;
+ BOOST_TEST( boost::addressof(x) == px );
+
+ const T& cx = *px;
+ const T* pcx = boost::addressof(cx);
+ BOOST_TEST( pcx == px );
+
+ volatile T& vx = *px;
+ volatile T* pvx = boost::addressof(vx);
+ BOOST_TEST( pvx == px );
+
+ const volatile T& cvx = *px;
+ const volatile T* pcvx = boost::addressof(cvx);
+ BOOST_TEST( pcvx == px );
+
+ delete px;
+}
+
+template<class T> void array_test( T * = 0 )
+{
+ T nrg[3] = {1,2,3};
+ T (*pnrg)[3] = &nrg;
+ BOOST_TEST( boost::addressof(nrg) == pnrg );
+
+ T const cnrg[3] = {1,2,3};
+ T const (*pcnrg)[3] = &cnrg;
+ BOOST_TEST( boost::addressof(cnrg) == pcnrg );
+}
+
+class convertible {
+public:
+
+ convertible( int = 0 )
+ {
+ }
+
+ template<class U> operator U () const
+ {
+ return U();
+ }
+};
+
+class convertible2 {
+public:
+
+ convertible2( int = 0 )
+ {
+ }
+
+ operator convertible2* () const
+ {
+ return 0;
+ }
+};
+
+int main()
+{
+ scalar_test<convertible>();
+ scalar_test<convertible2>();
+
+ array_test<convertible>();
+ array_test<convertible2>();
+
+ return boost::report_errors();
+}
Modified: trunk/libs/utility/test/Jamfile.v2
==============================================================================
--- trunk/libs/utility/test/Jamfile.v2 (original)
+++ trunk/libs/utility/test/Jamfile.v2 2009-03-20 13:14:00 EDT (Fri, 20 Mar 2009)
@@ -11,7 +11,9 @@
# Please keep the tests ordered by filename
test-suite utility
:
+ [ run ../addressof_fn_test.cpp ]
[ run ../addressof_test.cpp ]
+ [ run ../addressof_test2.cpp ]
[ run ../assert_test.cpp ]
[ run ../base_from_member_test.cpp ]
[ run ../binary_search_test.cpp ]
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk