[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New macro AC_FC_IMPLICIT_NONE to disable Fortran implicit int.
From: |
Ralf Wildenhues |
Subject: |
Re: New macro AC_FC_IMPLICIT_NONE to disable Fortran implicit int. |
Date: |
Sat, 5 Mar 2011 09:37:55 +0100 |
User-agent: |
Mutt/1.5.20 (2010-08-04) |
* Eric Blake wrote on Tue, Mar 01, 2011 at 08:54:50PM CET:
> On 02/27/2011 09:18 AM, Ralf Wildenhues wrote:
> > Another fairly simple Fortran macro, with data gathered from manuals
> > and from the overview site which Eve-Marie linked to.
> Same comments as the last patch, including:
>
> >
> > address@hidden AC_FC_IMPLICIT_NONE (@ovar{action-if-success},
> > @ovar{action-if-failure})
>
> should this use @dvar{action-if-failure, AC_MSG_FAILURE}?
Yes, thanks.
This is one of the macros that is not only useful for Fortran 77, but
also easy to port (as the code is already Fortran 77). So I went ahead
and factored it into AC_{F77,FC}_IMPLICIT_NONE.
I also fixed the autoconf.texi entry to not end up on the section about
Go. Added switches for a few more compilers. Added a print use of the
variable to avoid warnings about unused variables (given sufficient
warning flags; thanks Tobias for the hint!).
I then noted that Intel ifort only warns but doesn't fail upon implicit
declarations. Gah! This compiler is really not easy to support: with
unknown command-line arguments, it only warns but does not fail. On the
upside, it has a somewhat elaborate set of flags to turn warnings into
errors '-warn errors' (mind you, it then still doesn't fail over unknown
command-line args) , but on the downside the machinery seems quite buggy
in that for example, adding '-warn stderrors' (which aims to _also_ warn
about standard-conformance errors) turns the exit status back into zero.
Command-line order does not matter. :-(
Since I'm not yet ready to get into the business of heuristically
comparing warning output from compilers, the macro tries both -u and
'-u -warn errors', in the hope that the user hasn't turned on other
warning flags yet.
Thanks for reading this far. Will push this in a minute.
Cheers,
Ralf
New macros AC_{F77,FC}_IMPLICIT_NONE to disable Fortran implicit int.
* lib/autoconf/fortran.m4 (_AC_FC_IMPLICIT_NONE): New internal
macro.
(AC_F77_IMPLICIT_NONE, AC_FC_IMPLICIT_NONE): New macros.
* doc/autoconf.texi (Fortran Compiler): Document them.
* NEWS: Update.
diff --git a/NEWS b/NEWS
index 0e36b87..6a1771d 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ GNU Autoconf NEWS - User visible changes.
- New and updated macros for Fortran support:
AC_FC_CHECK_BOUNDS to enable array bounds checking
+ AC_F77_IMPLICIT_NONE and AC_FC_IMPLICIT_NONE to disable implicit integer
* Noteworthy changes in release 2.68 (2010-09-22) [stable]
Released by Eric Blake, based on git versions 2.67.*.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index e9bd85d..273fa60 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8259,6 +8259,19 @@ Fortran Compiler
message.
@end defmac
address@hidden AC_F77_IMPLICIT_NONE (@ovar{action-if-success}, @
+ @dvar{action-if-failure, AC_MSG_FAILURE})
address@hidden AC_FC_IMPLICIT_NONE (@ovar{action-if-success}, @
+ @dvar{action-if-failure, AC_MSG_FAILURE})
address@hidden
address@hidden
+
+Try to disallow implicit declarations in the Fortran compiler. If
+successful, the @var{action-if-success} is called and any needed flags
+are added to @code{FCFLAGS}. Otherwise, @var{action-if-failure} is
+called, which defaults to failing with an error message.
address@hidden defmac
+
@node Go Compiler
@subsection Go Compiler Characteristics
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 180fc6d..14e1c9c 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1446,3 +1446,75 @@ else
fi
AC_LANG_POP([Fortran])dnl
])# AC_FC_CHECK_BOUNDS
+
+
+# _AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
+# ------------------------------------------------------------------------
+# Look for a flag to disallow implicit declarations, and add it to FCFLAGS.
+# Call ACTION-IF-SUCCESS (defaults to nothing) if successful and
+# ACTION-IF-FAILURE (defaults to failing with an error message) if not.
+#
+# Known flags:
+# GNU gfortran, g95: -fimplicit-none, g77: -Wimplicit
+# Intel: -u, -implicitnone; might also need '-warn errors' to turn into error.
+# Sun/Oracle: -u
+# HP: +implicit_none
+# IBM: -u, -qundef
+# SGI: -u
+# Compaq: -u, -warn declarations
+# NAGWare: -u
+# Lahey: -in, --in, -AT
+# Cray: -Mdclchk -d i
+# PGI: -Mcdlchk
+# f2c: -u
+AC_DEFUN([_AC_FC_IMPLICIT_NONE],
+[_AC_FORTRAN_ASSERT()dnl
+AC_CACHE_CHECK([for flag to disallow _AC_LANG implicit declarations],
+ [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none],
+[ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=unknown
+ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save=$[]_AC_LANG_PREFIX[]FLAGS
+for ac_flag in none -fimplicit-none -u -Wimplicit -implicitnone +implicit_none
\
+ -qundef "-warn declarations" -in --in -AT "-d i" -Mdclchk \
+ "-u -warn errors"
+do
+ if test "x$ac_flag" != xnone; then
+ _AC_LANG_PREFIX[]FLAGS="$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save
$ac_flag"
+ fi
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
+ i = 0
+ print *, i]])],
+ [],
+ [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=$ac_flag; break])])
+done
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+_AC_LANG_PREFIX[]FLAGS=$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save
+])
+if test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" = xunknown; then
+ m4_default([$3],
+ [AC_MSG_ERROR([no Fortran flag to disallow implicit declarations found],
77)])
+else
+ if test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" != xnone; then
+ _AC_LANG_PREFIX[]FLAGS="$_AC_LANG_PREFIX[]FLAGS
$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none"
+ fi
+ $2
+fi
+])# _AC_FC_IMPLICIT_NONE
+
+
+# AC_F77_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
+# ------------------------------------------------------------------------
+AC_DEFUN([AC_F77_IMPLICIT_NONE],
+[AC_LANG_PUSH([Fortran 77])dnl
+_AC_FC_IMPLICIT_NONE($@)
+AC_LANG_POP([Fortran 77])dnl
+])# AC_F77_IMPLICIT_NONE
+
+
+# AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
+# -----------------------------------------------------------------------
+AC_DEFUN([AC_FC_IMPLICIT_NONE],
+[AC_LANG_PUSH([Fortran])dnl
+_AC_FC_IMPLICIT_NONE($@)
+AC_LANG_POP([Fortran])dnl
+])# AC_FC_IMPLICIT_NONE