1
1

It appears that most versions of the IBM XL compiler (including the latest

releases on Linux and OS X) don't handle const_cast<> of 2-dimensional 
arrays properly.  If we're using one of the compilers that isn't friendly
to such casts, fall back to a standard C-style cast.

refs: 

This commit was SVN r11263.
Этот коммит содержится в:
Brian Barrett 2006-08-19 22:55:59 +00:00
родитель 943e7dcfba
Коммит 1daa21e1e3
3 изменённых файлов: 39 добавлений и 2 удалений

@ -183,6 +183,28 @@ AC_DEFUN([OMPI_SETUP_CXX],[
;;
esac
# see if the compiler supports const_cast of 2-dimensional arrays
AC_LANG_PUSH(C++)
AC_CACHE_CHECK([if $CXX supports const_cast<> properly],
[ompi_cv_cxx_supports_2d_const_cast],
[AC_TRY_COMPILE([int non_const_func(int ranges[][3]);
int cast_test(const int ranges[][3]) {
return non_const_func(const_cast<int(*)[3]>(ranges));
}],
[],
[ompi_cv_cxx_supports_2d_const_cast="yes"],
[ompi_cv_cxx_supports_2d_const_cast="no"])])
if test "$ompi_cv_cxx_supports_2d_const_cast" = "yes" ; then
use_2d_const_cast=1
else
use_2d_const_cast=0
fi
AC_DEFINE_UNQUOTED([OMPI_CXX_SUPPORTS_2D_CONST_CAST],
[$use_2d_const_cast],
[Whether a const_cast on a 2-d array will work with the C++ compiler])
unset use_2d_const_cast
AC_LANG_POP(C++)
# Note: gcc-imperonating compilers accept -O3
if test "$WANT_DEBUG" = "1"; then
OPTFLAGS=

@ -74,6 +74,9 @@
/* Whether we want MPI cxx support or not */
#undef OMPI_WANT_CXX_BINDINGS
/* Whether a const_cast on a 2-d array will work with the C++ compiler */
#undef OMPI_CXX_SUPPORTS_2D_CONST_CAST
/* Whether we want the MPI f77 bindings or not */
#undef OMPI_WANT_F77_BINDINGS

@ -97,7 +97,13 @@ inline MPI::Group
MPI::Group::Range_incl(int n, const int ranges[][3]) const
{
MPI_Group newgroup;
(void)MPI_Group_range_incl(mpi_group, n, const_cast<int(*)[3]>(ranges), &newgroup);
(void)MPI_Group_range_incl(mpi_group, n,
#if OMPI_CXX_SUPPORTS_2D_CONST_CAST
const_cast<int(*)[3]>(ranges),
#else
(int(*)[3]) ranges,
#endif
&newgroup);
return newgroup;
}
@ -105,7 +111,13 @@ inline MPI::Group
MPI::Group::Range_excl(int n, const int ranges[][3]) const
{
MPI_Group newgroup;
(void)MPI_Group_range_excl(mpi_group, n, const_cast<int(*)[3]>(ranges), &newgroup);
(void)MPI_Group_range_excl(mpi_group, n,
#if OMPI_CXX_SUPPORTS_2D_CONST_CAST
const_cast<int(*)[3]>(ranges),
#else
(int(*)[3]) ranges,
#endif
&newgroup);
return newgroup;
}