From: wolf Date: Mon, 30 Sep 2002 17:12:20 +0000 (+0000) Subject: Try to work around some hairy problems with different compilers interpreting parts... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=844da068d10f86844d9872e53556084422fa4723;p=dealii-svn.git Try to work around some hairy problems with different compilers interpreting parts of the standard relating to template specializations and friend declarations differently. git-svn-id: https://svn.dealii.org/trunk@6563 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/aclocal.m4 b/deal.II/aclocal.m4 index d5a0bc0721..1cbad63afa 100644 --- a/deal.II/aclocal.m4 +++ b/deal.II/aclocal.m4 @@ -1783,6 +1783,66 @@ AC_DEFUN(DEAL_II_CHECK_NAMESP_TEMPL_FRIEND_BUG, dnl +dnl ------------------------------------------------------------- +dnl In some cases, we would like to name partial specializations +dnl as friends. However, the standard forbids us to do so. But +dnl then, we can declare the general template as a friend, and +dnl at least gcc extends the friendship to all specializations +dnl of the templates, which is not what the standard says. +dnl +dnl With other compilers, most notably cxx, this does not work. +dnl In this case, we can make individual specializations friends, +dnl which in turn gcc rejects. So check, whether this is possible. +dnl +dnl The respective clause in the standard is 14.5.3.1, which gives +dnl this example: +dnl template class task { +dnl friend class task; +dnl }; +dnl +dnl +dnl Usage: DEAL_II_CHECK_TEMPL_SPEC_FRIEND_BUG +dnl +dnl ------------------------------------------------------------- +AC_DEFUN(DEAL_II_CHECK_TEMPL_SPEC_FRIEND_BUG, dnl +[ + AC_MSG_CHECKING(for template specialization friend bug) + AC_LANG(C++) + CXXFLAGS="$CXXFLAGSG" + AC_TRY_COMPILE( + [ +template class X; +template class X<1,T>; + +template class Y { + static int i; + template friend class X; + friend class X<1,P>; +}; + +template class X<1,T> { + X () { Y::i; }; // access private field +}; + +template class X<1,int>; + ], + [], + [ + AC_MSG_RESULT(no) + ], + [ + AC_MSG_RESULT(yes) + AC_DEFINE_UNQUOTED(DEAL_II_TEMPL_SPEC_FRIEND_BUG, 1, + [Define if we have to work around a bug with some + compilers that will not allow us to specify a + fully specialized class of a template as a friend. + See the aclocal.m4 file in the top-level directory + for a description of this bug.]) + ]) +]) + + + dnl ------------------------------------------------------------- dnl Intel's ICC 5.0.1 compiler has the following problem: it won't dnl compile this code: diff --git a/deal.II/base/include/base/table.h b/deal.II/base/include/base/table.h index f77f470c82..95d8adac21 100644 --- a/deal.II/base/include/base/table.h +++ b/deal.II/base/include/base/table.h @@ -452,9 +452,13 @@ namespace TableBaseAccessors template friend class Table; template friend class Accessor; -#else +# ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG + friend class Table; friend class Accessor; +# endif +#else friend class Table; + friend class Accessor; #endif }; diff --git a/deal.II/configure b/deal.II/configure index ab37d73e68..a8134225a6 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 1.122 . +# From configure.in Revision: 1.123 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.53a. # @@ -4132,6 +4132,80 @@ cat >>confdefs.h <<_ACEOF _ACEOF +fi +rm -f conftest.$ac_objext conftest.$ac_ext + + + echo "$as_me:$LINENO: checking for template specialization friend bug" >&5 +echo $ECHO_N "checking for template specialization friend bug... $ECHO_C" >&6 + ac_ext=cc +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + CXXFLAGS="$CXXFLAGSG" + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" + +template class X; +template class X<1,T>; + +template class Y { + static int i; + template friend class X; + friend class X<1,P>; +}; + +template class X<1,T> { + X () { Y::i; }; // access private field +}; + +template class X<1,int>; + +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 + + echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + +cat >>confdefs.h <<_ACEOF +#define DEAL_II_TEMPL_SPEC_FRIEND_BUG 1 +_ACEOF + + fi rm -f conftest.$ac_objext conftest.$ac_ext diff --git a/deal.II/configure.in b/deal.II/configure.in index fa3b2bc404..64a32d6692 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -167,6 +167,7 @@ DEAL_II_CHECK_LOCAL_TYPEDEF_COMP DEAL_II_CHECK_TEMPLATE_SPEC_ACCESS DEAL_II_CHECK_MEMBER_OP_TEMPLATE_INST DEAL_II_CHECK_NAMESP_TEMPL_FRIEND_BUG +DEAL_II_CHECK_TEMPL_SPEC_FRIEND_BUG DEAL_II_CHECK_TEMPL_CONST_MEM_PTR_BUG DEAL_II_CHECK_CONST_MEM_FUN_PTR_BUG DEAL_II_CHECK_IMPLEMENTED_PURE_FUNCTION_BUG