From ae19cd6236578f40c52c088470aeceeaceecce52 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Mon, 14 Mar 2005 23:03:42 +0000 Subject: [PATCH] work-around for Borland addressof(array) bug and associated tests [SVN r27656] --- addressof_test.cpp | 10 +++++++++- include/boost/utility/addressof.hpp | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/addressof_test.cpp b/addressof_test.cpp index 2630f27..51294bd 100644 --- a/addressof_test.cpp +++ b/addressof_test.cpp @@ -36,6 +36,14 @@ int test_main(int, char*[]) 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; } diff --git a/include/boost/utility/addressof.hpp b/include/boost/utility/addressof.hpp index 603ea60..6d97fca 100644 --- a/include/boost/utility/addressof.hpp +++ b/include/boost/utility/addressof.hpp @@ -33,6 +33,22 @@ addressof(T& v) &const_cast(reinterpret_cast(v))); } +// Borland doesn't like casting an array reference to a char reference +// but these overloads work around the problem. +# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +template +T (*addressof(T (&t)[N]))[N] +{ + return reinterpret_cast(&t); +} + +template +const T (*addressof(const T (&t)[N]))[N] +{ + return reinterpret_cast(&t); +} +# endif + } #endif // BOOST_UTILITY_ADDRESSOF_HPP