From: bangerth Date: Tue, 28 Aug 2012 17:50:13 +0000 (+0000) Subject: Figure out a flag that can be used to deprecate functions. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f497f85ad70ca14281d32faee1301c5eaebb342e;p=dealii-svn.git Figure out a flag that can be used to deprecate functions. git-svn-id: https://svn.dealii.org/trunk@26148 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/aclocal.m4 b/deal.II/aclocal.m4 index 73d5fafe1f..8fbe0c44b4 100644 --- a/deal.II/aclocal.m4 +++ b/deal.II/aclocal.m4 @@ -435,8 +435,10 @@ AC_DEFUN(DEAL_II_SET_CXX_FLAGS, dnl dnl BOOST uses long long, so don't warn about this CXXFLAGSG="$CXXFLAGSG -Wno-long-long" - dnl See whether the gcc we use already has a flag for C++2011 features. + dnl See whether the gcc we use already has a flag for C++2011 features + dnl and whether we can mark functions as deprecated with an attributed DEAL_II_CHECK_CXX1X + DEAL_II_CHECK_DEPRECATED dnl On some gcc 4.3 snapshots, a 'const' qualifier on a return type triggers a @@ -1336,6 +1338,74 @@ AC_DEFUN(DEAL_II_CHECK_CXX1X_COMPONENTS, dnl ]) + +dnl ------------------------------------------------------------- +dnl See if the compiler understands the attribute to mark functions +dnl as deprecated. +dnl +dnl Usage: DEAL_II_CHECK_DEPRECATED +dnl +dnl ------------------------------------------------------------- +AC_DEFUN(DEAL_II_CHECK_DEPRECATED, dnl +[ + AC_MSG_CHECKING(whether compiler has attributes to deprecate functions) + + + OLD_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="" + + dnl First see if the following compiles without error (it should + dnl produce a warning but we don't care about this + AC_TRY_COMPILE( + [ + int old_fn () __attribute__((deprecated)); + int old_fn (); + int (*fn_ptr)() = old_fn; + ], + [;], + [ + test1=yes + ], + [ + test1=no + ]) + + dnl Now try this again with -Werror. It should now fail + CXXFLAGS=-Werror + AC_TRY_COMPILE( + [ + int old_fn () __attribute__((deprecated)); + int old_fn (); + int (*fn_ptr)() = old_fn; + ], + [;], + [ + test2=yes + ], + [ + test2=no + ]) + CXXFLAGS="${OLD_CXXFLAGS}" + + if test "$test1$test2" = "yesno" ; then + AC_MSG_RESULT(yes) + AC_DEFINE(DEAL_II_DEPRECATED, [__attribute__((deprecated))], + [If the compiler supports this, then this variable is + defined to a string that when written after a function + name makes the compiler emit a warning whenever this + function is used somewhere that its use is deprecated.]) + else + AC_MSG_RESULT(no) + AC_DEFINE(DEAL_II_DEPRECATED, [], + [If the compiler supports this, then this variable is + defined to a string that when written after a function + name makes the compiler emit a warning whenever this + function is used somewhere that its use is deprecated.]) + fi +]) + + + dnl ------------------------------------------------------------- dnl Determine the C compiler in use. Return the name and possibly dnl version of this compiler in CC_VERSION. This function is almost diff --git a/deal.II/configure b/deal.II/configure index 6cbe57e52a..2dc9370956 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -4515,6 +4515,82 @@ $as_echo "no" >&6; } fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler has attributes to deprecate functions" >&5 +$as_echo_n "checking whether compiler has attributes to deprecate functions... " >&6; } + + + OLD_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="" + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + int old_fn () __attribute__((deprecated)); + int old_fn (); + int (*fn_ptr)() = old_fn; + +int +main () +{ +; + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + + test1=yes + +else + + test1=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + CXXFLAGS=-Werror + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + int old_fn () __attribute__((deprecated)); + int old_fn (); + int (*fn_ptr)() = old_fn; + +int +main () +{ +; + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + + test2=yes + +else + + test2=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CXXFLAGS="${OLD_CXXFLAGS}" + + if test "$test1$test2" = "yesno" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define DEAL_II_DEPRECATED __attribute__((deprecated))" >>confdefs.h + + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +$as_echo "#define DEAL_II_DEPRECATED /**/" >>confdefs.h + + fi + + CXXFLAGS="-Wreturn-type -Werror" { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether qualifiers in return types lead to a warning" >&5 diff --git a/deal.II/include/deal.II/base/config.h.in b/deal.II/include/deal.II/base/config.h.in index 4e3186b635..a0a9a5346a 100644 --- a/deal.II/include/deal.II/base/config.h.in +++ b/deal.II/include/deal.II/base/config.h.in @@ -105,6 +105,11 @@ member functions. */ #undef DEAL_II_CONST_MEMBER_DEDUCTION_BUG +/* If the compiler supports this, then this variable is defined to a string + that when written after a function name makes the compiler emit a warning + whenever this function is used somewhere that its use is deprecated. */ +#undef DEAL_II_DEPRECATED + /* disable the function parser in contrib */ #undef DEAL_II_DISABLE_PARSER