From dcb2dd4736d1aea213b5de7249267911c8e21a6c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 16 Mar 2005 22:02:22 +0000 Subject: [PATCH] Removed type_traits include, added more tests [SVN r27712] --- addressof_test.cpp | 99 +++++++++++++++++++++-------- include/boost/utility/addressof.hpp | 12 ++-- test/Jamfile | 2 +- test/Jamfile.v2 | 2 +- 4 files changed, 82 insertions(+), 33 deletions(-) diff --git a/addressof_test.cpp b/addressof_test.cpp index 51294bd..9619cc3 100644 --- a/addressof_test.cpp +++ b/addressof_test.cpp @@ -7,43 +7,88 @@ // For more information, see http://www.boost.org -#define BOOST_INCLUDE_MAIN -#include -#include + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + +#include + +template 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 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 ); +} + +struct addressable +{ + addressable( int = 0 ) + { + } +}; struct useless_type {}; class nonaddressable { public: - void dummy(); // Silence GCC warning: all member of class are private + + nonaddressable( int = 0 ) + { + } + + void dummy(); // Silence GCC warning: all member of class are private private: - useless_type operator&() const; + + useless_type operator&() const; }; -int test_main(int, char*[]) +int main() { - nonaddressable* px = new nonaddressable(); + scalar_test(); + scalar_test(); + scalar_test(); + scalar_test(); - nonaddressable& x = *px; - BOOST_CHECK(boost::addressof(x) == px); + array_test(); + array_test(); + array_test(); + array_test(); - const nonaddressable& cx = *px; - BOOST_CHECK(boost::addressof(cx) == static_cast(px)); - - volatile nonaddressable& vx = *px; - BOOST_CHECK(boost::addressof(vx) == static_cast(px)); - - const volatile nonaddressable& cvx = *px; - BOOST_CHECK(boost::addressof(cvx) == static_cast(px)); - - int nrg[3] = {1,2,3}; - int (*pnrg)[3] = &nrg; - BOOST_CHECK(boost::addressof(nrg) == pnrg); - - int const cnrg[3] = {1,2,3}; - int const (*pcnrg)[3] = &cnrg; - BOOST_CHECK(boost::addressof(cnrg) == pcnrg); - - return 0; + return boost::report_errors(); } diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 6d97fca..7629488 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -13,9 +13,6 @@ # include # include -# if BOOST_WORKAROUND(BOOST_MSVC, == 1300) -# include -# endif namespace boost { @@ -23,7 +20,14 @@ namespace boost { // VC7 strips const from nested classes unless we add indirection here # if BOOST_WORKAROUND(BOOST_MSVC, == 1300) -template typename add_pointer::type + +template struct _addp +{ + typedef T * type; +}; + +template typename _addp::type + # else template T* # endif diff --git a/test/Jamfile b/test/Jamfile index c07b307..89d77d0 100755 --- a/test/Jamfile +++ b/test/Jamfile @@ -19,7 +19,7 @@ local test_monitor = @boost/libs/test/build/boost_test_exec_monitor ; # Please keep the tests ordered by filename test-suite utility : - [ run ../addressof_test.cpp $(test_monitor) ] + [ run ../addressof_test.cpp ] [ run ../assert_test.cpp ] [ run ../base_from_member_test.cpp ] [ run ../binary_search_test.cpp ] diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d1ab6f3..493011d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -12,7 +12,7 @@ import testing ; # Please keep the tests ordered by filename test-suite utility : - [ run ../addressof_test.cpp ../../test/build//boost_test_exec_monitor ] + [ run ../addressof_test.cpp ] [ run ../assert_test.cpp ] [ run ../base_from_member_test.cpp ] [ run ../binary_search_test.cpp ]