]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Try to work around some hairy problems with different compilers interpreting parts...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 30 Sep 2002 17:12:20 +0000 (17:12 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 30 Sep 2002 17:12:20 +0000 (17:12 +0000)
git-svn-id: https://svn.dealii.org/trunk@6563 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/aclocal.m4
deal.II/base/include/base/table.h
deal.II/configure
deal.II/configure.in

index d5a0bc0721601a584090a5e6069e77be311bc099..1cbad63afa2242bfe6bb18fe42710c11108183df 100644 (file)
@@ -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 T> class task {
+dnl     friend class task<int>;
+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 <int N, typename T> class X;
+template <typename T>        class X<1,T>;
+
+template <typename P> class Y {
+    static int i;
+    template <int N, typename T> friend class X;
+    friend class X<1,P>;
+};
+
+template <typename T> class X<1,T> {
+    X () { Y<T>::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:
index f77f470c82df09343ec92f2628f373dcb3f38d5f..95d8adac21cb9b6fcc4bb856602cb6bee45d9b89 100644 (file)
@@ -452,9 +452,13 @@ namespace TableBaseAccessors
       template <int N1, typename T1> friend class Table;
       template <int N1, typename T1, bool C1, unsigned int P1>
       friend class Accessor;
-#else
+#  ifndef DEAL_II_TEMPL_SPEC_FRIEND_BUG
+      friend class Table<N,T>;
       friend class Accessor<N,T,C,P+1>;
+#  endif
+#else
       friend class Table<N,T>;
+      friend class Accessor<N,T,C,P+1>;
 #endif
   };
 
index ab37d73e68a1d833a9d4f0b65a0dd71a6ab77905..a8134225a668665ef0c7bfc82514ea994a3bf03e 100755 (executable)
@@ -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 <int N, typename T> class X;
+template <typename T>        class X<1,T>;
+
+template <typename P> class Y {
+    static int i;
+    template <int N, typename T> friend class X;
+    friend class X<1,P>;
+};
+
+template <typename T> class X<1,T> {
+    X () { Y<T>::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
 
index fa3b2bc404d27666e3f13f4476231cc242adf663..64a32d6692d7681211b044d4e16a6f97120c7f97 100644 (file)
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.