From be0870519f9910fb700624a476af515d5861424d Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 22 Oct 2003 23:51:13 +0000 Subject: [PATCH] Detect and work around a bug in an old version of gcc. git-svn-id: https://svn.dealii.org/trunk@8137 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/aclocal.m4 | 34 +++++++++++++++ deal.II/base/include/base/config.h.in | 23 ++++++++++ deal.II/configure | 63 +++++++++++++++++++++++++++ deal.II/configure.in | 24 ++++++++++ 4 files changed, 144 insertions(+) diff --git a/deal.II/aclocal.m4 b/deal.II/aclocal.m4 index c40b5a92ee..4a2337b0db 100644 --- a/deal.II/aclocal.m4 +++ b/deal.II/aclocal.m4 @@ -2629,6 +2629,40 @@ AC_DEFUN(DEAL_II_CHECK_SFINAE_BUG, dnl +dnl ------------------------------------------------------------- +dnl Old versions of gcc had a problem with arrays inside ?: +dnl expressions: they decayed too quickly to pointers. This then +dnl leads to erroneous warnings :-( +dnl +dnl Usage: DEAL_II_CHECK_ARRAY_CONDITIONAL_DECAY_BUG +dnl +dnl ------------------------------------------------------------- +AC_DEFUN(DEAL_II_CHECK_ARRAY_CONDITIONAL_DECAY_BUG, dnl +[ + AC_MSG_CHECKING(for array assignment in conditional bug) + AC_LANG(C++) + CXXFLAGS="-W -Wall -Werror" + AC_TRY_COMPILE( + [ + ], + [ + const int x[2][2] = {{1,1},{1,1}}; + const int (&y)[2] = (1 ? x[0] : x[1]); + return y[0]; + ], + [ + AC_MSG_RESULT(no) + ], + [ + AC_MSG_RESULT(yes) + AC_DEFINE(DEAL_II_ARRAY_CONDITIONAL_DECAY_BUG, 1, + [Defined if the compiler has a problem with + assigning arrays in conditionals]) + ]) +]) + + + 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 86146093d1..253ee80ccb 100644 --- a/deal.II/base/include/base/config.h.in +++ b/deal.II/base/include/base/config.h.in @@ -230,8 +230,31 @@ * The constants defined here are a subset of the @p{M_XXX} constants sometimes * declared in the system include file @p{math.h}, but without the * prefix @p{M_}. + * + * In addition to that, we declare @p{invalid_unsigned_int} to be the + * largest unsigned integer representable; this value is widely used in + * the library as a marker for an invalid index, an invalid size of an + * array, and similar purposes. */ namespace deal_II_numbers { + /** + * Representation of the + * largest number that + * can be put into an + * unsigned integer. This + * value is widely used + * throughout the library + * as a marker for an + * invalid unsigned + * integer value, such as + * an invalid array + * index, an invalid + * array size, and the + * like. + */ + static const unsigned int + invalid_unsigned_int = static_cast (-1); + /** * e */ diff --git a/deal.II/configure b/deal.II/configure index 20fc6e872a..b6e66aae03 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -5102,6 +5102,69 @@ cat >>confdefs.h <<\_ACEOF _ACEOF +fi +rm -f conftest.$ac_objext conftest.$ac_ext + + + echo "$as_me:$LINENO: checking for array assignment in conditional bug" >&5 +echo $ECHO_N "checking for array assignment in conditional 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="-W -Wall -Werror" + 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. */ + + +int +main () +{ + + const int x[2][2] = {{1,1},{1,1}}; + const int (&y)[2] = (1 ? x[0] : x[1]); + return y[0]; + + ; + 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" >&5 +echo "${ECHO_T}yes" >&6 + +cat >>confdefs.h <<\_ACEOF +#define DEAL_II_ARRAY_CONDITIONAL_DECAY_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 51402e25de..47f5de4ad2 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -179,6 +179,7 @@ DEAL_II_CHECK_MEMBER_VAR_SPECIALIZATION_BUG DEAL_II_CHECK_LONG_DOUBLE_LOOP_BUG DEAL_II_CHECK_ANON_NAMESPACE_BUG DEAL_II_CHECK_SFINAE_BUG +DEAL_II_CHECK_ARRAY_CONDITIONAL_DECAY_BUG DEAL_II_CHECK_BOOST_SHARED_PTR_ASSIGNMENT DEAL_II_HAVE_PRETTY_FUNCTION DEAL_II_HAVE_STD_ITERATOR @@ -436,8 +437,31 @@ AH_BOTTOM( * The constants defined here are a subset of the @p{M_XXX} constants sometimes * declared in the system include file @p{math.h}, but without the * prefix @p{M_}. + * + * In addition to that, we declare @p{invalid_unsigned_int} to be the + * largest unsigned integer representable; this value is widely used in + * the library as a marker for an invalid index, an invalid size of an + * array, and similar purposes. */ namespace deal_II_numbers { + /** + * Representation of the + * largest number that + * can be put into an + * unsigned integer. This + * value is widely used + * throughout the library + * as a marker for an + * invalid unsigned + * integer value, such as + * an invalid array + * index, an invalid + * array size, and the + * like. + */ + static const unsigned int + invalid_unsigned_int = static_cast (-1); + /** * e */ -- 2.39.5