diff --git a/config/ompi_setup_cxx.m4 b/config/ompi_setup_cxx.m4 index 8b850f9e50..d44062154a 100644 --- a/config/ompi_setup_cxx.m4 +++ b/config/ompi_setup_cxx.m4 @@ -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(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= diff --git a/ompi/include/mpi.h.in b/ompi/include/mpi.h.in index d4552425b3..3e87686107 100644 --- a/ompi/include/mpi.h.in +++ b/ompi/include/mpi.h.in @@ -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 diff --git a/ompi/mpi/cxx/group_inln.h b/ompi/mpi/cxx/group_inln.h index 5132a22cc1..c363fb1067 100644 --- a/ompi/mpi/cxx/group_inln.h +++ b/ompi/mpi/cxx/group_inln.h @@ -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(ranges), &newgroup); + (void)MPI_Group_range_incl(mpi_group, n, +#if OMPI_CXX_SUPPORTS_2D_CONST_CAST + const_cast(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(ranges), &newgroup); + (void)MPI_Group_range_excl(mpi_group, n, +#if OMPI_CXX_SUPPORTS_2D_CONST_CAST + const_cast(ranges), +#else + (int(*)[3]) ranges, +#endif + &newgroup); return newgroup; }