1 // Copyright (C) 2002 Brad King (brad.king@kitware.com) 2 // Douglas Gregor (gregod@cs.rpi.edu) 3 // 4 // Copyright 2009 Peter Dimov 5 // 6 // Distributed under the Boost Software License, Version 1.0. (See 7 // accompanying file LICENSE_1_0.txt or copy at 8 // http://www.boost.org/LICENSE_1_0.txt) 9 10 // For more information, see http://www.boost.org 11 12 13 #include <boost/utility/addressof.hpp> 14 15 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) 16 #pragma warning(push, 3) 17 #endif 18 19 #include <iostream> 20 21 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) 22 #pragma warning(pop) 23 #endif 24 25 #include <boost/core/lightweight_test.hpp> 26 scalar_test(T * =0)27template<class T> void scalar_test( T * = 0 ) 28 { 29 T* px = new T(); 30 31 T& x = *px; 32 BOOST_TEST( boost::addressof(x) == px ); 33 34 const T& cx = *px; 35 const T* pcx = boost::addressof(cx); 36 BOOST_TEST( pcx == px ); 37 38 volatile T& vx = *px; 39 volatile T* pvx = boost::addressof(vx); 40 BOOST_TEST( pvx == px ); 41 42 const volatile T& cvx = *px; 43 const volatile T* pcvx = boost::addressof(cvx); 44 BOOST_TEST( pcvx == px ); 45 46 delete px; 47 } 48 array_test(T * =0)49template<class T> void array_test( T * = 0 ) 50 { 51 T nrg[3] = {1,2,3}; 52 T (*pnrg)[3] = &nrg; 53 BOOST_TEST( boost::addressof(nrg) == pnrg ); 54 55 T const cnrg[3] = {1,2,3}; 56 T const (*pcnrg)[3] = &cnrg; 57 BOOST_TEST( boost::addressof(cnrg) == pcnrg ); 58 } 59 60 class convertible { 61 public: 62 convertible(int=0)63 convertible( int = 0 ) 64 { 65 } 66 operator U() const67 template<class U> operator U () const 68 { 69 return U(); 70 } 71 }; 72 73 class convertible2 { 74 public: 75 convertible2(int=0)76 convertible2( int = 0 ) 77 { 78 } 79 operator convertible2*() const80 operator convertible2* () const 81 { 82 return 0; 83 } 84 }; 85 main()86int main() 87 { 88 scalar_test<convertible>(); 89 scalar_test<convertible2>(); 90 91 array_test<convertible>(); 92 array_test<convertible2>(); 93 94 return boost::report_errors(); 95 } 96