From: Wolfgang Bangerth Date: Thu, 5 Feb 2004 22:39:57 +0000 (+0000) Subject: Test for yet another compiler bug. X-Git-Tag: v8.0.0~15839 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94e3e5c17098251d68a216ecbdbc7aa2ad13a4ec;p=dealii.git Test for yet another compiler bug. git-svn-id: https://svn.dealii.org/trunk@8401 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/aclocal.m4 b/deal.II/aclocal.m4 index d247ffef7c..a17ac6a941 100644 --- a/deal.II/aclocal.m4 +++ b/deal.II/aclocal.m4 @@ -2714,6 +2714,66 @@ AC_DEFUN(DEAL_II_CHECK_ARRAY_CONDITIONAL_DECAY_BUG, dnl +dnl ------------------------------------------------------------- +dnl Some versions of gcc get this example wrong: +dnl --------------------------------- +dnl struct X +dnl { +dnl template void operator << (T); +dnl }; +dnl +dnl void f() +dnl { +dnl X x; +dnl x.operator << (1); +dnl } +dnl --------------------------------- +dnl They want to see a "template" for disambiguation in +dnl x.template operator << (1); +dnl which shouldn't be necessary since the left hand side of the +dnl dot operator is not template dependent. Surprisingly, this is +dnl only the case for operators, not if operator<< were a regular +dnl function. Annoyingly, other compilers barf on seeing the +dnl disambiguating "template" keyword. +dnl +dnl Usage: DEAL_II_CHECK_TEMPL_OP_DISAMBIGUATION_BUG +dnl +dnl ------------------------------------------------------------- +AC_DEFUN(DEAL_II_CHECK_TEMPL_OP_DISAMBIGUATION_BUG, dnl +[ + AC_MSG_CHECKING(for template operator disambiguation bug) + AC_LANG(C++) + CXXFLAGS="$CXXFLAGSG" + AC_TRY_COMPILE( + [ + struct X + { + template void operator << (T); + }; + + void f() + { + X x; + x.operator << (1); + } + ], + [], + [ + AC_MSG_RESULT(no) + ], + [ + AC_MSG_RESULT(yes. using workaround) + AC_DEFINE(DEAL_II_TEMPL_OP_DISAMBIGUATION_BUG, 1, + [Defined if the compiler requires the use of the + template keyword for disambiguation keyword in + certain contexts in which it is not supposed to + do so. For the exact failure mode, look at + aclocal.m4 in the top-level directory.]) + ]) +]) + + + dnl ------------------------------------------------------------- dnl The boost::shared_ptr class has a templated assignment operator dnl but no assignment operator matching the default operator diff --git a/deal.II/base/include/base/config.h.in b/deal.II/base/include/base/config.h.in index d97bb2eb5f..68e1588343 100644 --- a/deal.II/base/include/base/config.h.in +++ b/deal.II/base/include/base/config.h.in @@ -136,6 +136,12 @@ the top-level directory. */ #undef DEAL_II_TEMPLATE_TEMPLATE_TYPEDEF_BUG +/* Defined if the compiler requires the use of the template keyword for + disambiguation keyword in certain contexts in which it is not supposed to + do so. For the exact failure mode, look at aclocal.m4 in the top-level + directory. */ +#undef DEAL_II_TEMPL_OP_DISAMBIGUATION_BUG + /* 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 diff --git a/deal.II/configure b/deal.II/configure index c415302363..3953dc5019 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 1.159 . +# From configure.in Revision: 1.160 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.57. # @@ -5131,6 +5131,75 @@ cat >>confdefs.h <<\_ACEOF _ACEOF +fi +rm -f conftest.$ac_objext conftest.$ac_ext + + + echo "$as_me:$LINENO: checking for template operator disambiguation bug" >&5 +echo $ECHO_N "checking for template operator disambiguation 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" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + struct X + { + template void operator << (T); + }; + + void f() + { + X x; + x.operator << (1); + } + +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 +sed 's/^/| /' conftest.$ac_ext >&5 + + + echo "$as_me:$LINENO: result: yes. using workaround" >&5 +echo "${ECHO_T}yes. using workaround" >&6 + +cat >>confdefs.h <<\_ACEOF +#define DEAL_II_TEMPL_OP_DISAMBIGUATION_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 d8e5b74be0..011720abd8 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -180,6 +180,7 @@ DEAL_II_CHECK_LONG_DOUBLE_LOOP_BUG DEAL_II_CHECK_ANON_NAMESPACE_BUG DEAL_II_CHECK_ANON_NAMESPACE_BUG2 DEAL_II_CHECK_SFINAE_BUG +DEAL_II_CHECK_TEMPL_OP_DISAMBIGUATION_BUG DEAL_II_CHECK_ARRAY_CONDITIONAL_DECAY_BUG DEAL_II_CHECK_BOOST_SHARED_PTR_ASSIGNMENT DEAL_II_HAVE_PRETTY_FUNCTION diff --git a/tests/tests.h b/tests/tests.h index 512091a461..e58998636a 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -16,7 +16,7 @@ // common definitions used in all the tests - +#include #include #include @@ -29,9 +29,17 @@ LogStream & operator << (LogStream &logstream, const double d) { if (std::fabs (d) < 1e-10) - logstream.operator << (0.); + logstream. +#ifdef DEAL_II_TEMPL_OP_DISAMBIGUATION_BUG + template +#endif + operator << (0.); else - logstream.operator << (d); + logstream. +#ifdef DEAL_II_TEMPL_OP_DISAMBIGUATION_BUG + template +#endif + operator << (d); return logstream; } @@ -41,9 +49,17 @@ LogStream & operator << (LogStream &logstream, const float d) { if (std::fabs (d) < 1e-8) - logstream.operator << (0.); + logstream. +#ifdef DEAL_II_TEMPL_OP_DISAMBIGUATION_BUG + template +#endif + operator << (0.); else - logstream.operator << (d); + logstream. +#ifdef DEAL_II_TEMPL_OP_DISAMBIGUATION_BUG + template +#endif + operator << (d); return logstream; }