This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] Add new -std=legacy command line option


The following patch refines the semantics of gfortran's extensions
into two categories; GFC_STD_GNU for useful functionality not defined
in any official fortran standard (i.e. stuff we're proud of) and
GFC_STD_LEGACY for functionality we're forced to support for backward
compatibility with other compilers and crusty dusty-deck fortran
(i.e. the stuff we're embarassed by).

Making this distiction allows us to fine-tune the default behaviour
of gfortran, to accept both kinds of extensions but to warn about
the latter.  This is the behaviour of -std=gnu.  As an enhancement
to shut up these warnings, I've also added -std=legacy which makes
a best effort to compile whatever it can without warnings.  I've
also allowed -pedantic to pretty much undo -std=legacy warning wise,
and effectively "-std=legacy -pedantic" is equivalent to "-std=gnu".


Although there are no users of this infrastructure yet, it should
resolve the LOGICAL <-> INTEGER conversion issue to everyone's
staisfaction and allow extensions such as using real numbers to
index arrays, or omitting commas to reclassified as GFC_STD_LEGACY.
These are really things that warning about, and writers of new code
should be exposed to these warnings even without specifying
-pedantic or -std=f95.

Before anyone asks about new test cases, my intention is that the
three (probably four or five) logint-N.f tests proposed in my parallel
patch will test that those warnings/errors are correctly diagnosed
by default, with -std=gnu, with -std=legacy, with -std=f95 and maybe
even with -pedantic throw in for good measure.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", including f95, and regression tested with a "make
check-gfortran" in the gcc/ directory and a top-level "make dvi" and
"make info".

Ok for mainline?

2005-05-28  Roger Sayle  <roger@eyesopen.com>

	* gfortran.h (GFC_STD_LEGACY): New "standard" macro.  Reindent.
	* options.c (gfc_init_options): By default, allow legacy extensions
	but warn about them.
	(gfc_post_options): Make -pedantic warn about legacy extensions
	even with -std=legacy.
	(gfc_handle_option): Make -std=gnu follow the default behaviour
	of warning about legacy extensions, but allowing them. Make the
	new -std=legacy accept everything and warn about nothing.
	* lang.opt (std=legacy): New F95 command line option.
	* invoke.texi: Document both -std=f2003 and -std=legacy.
	* gfortran.texi: Explain the two types of extensions and document
	how they are affected by the various -std= command line options.


Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.69
diff -c -3 -p -r1.69 gfortran.h
*** gfortran.h	10 May 2005 22:06:43 -0000	1.69
--- gfortran.h	28 May 2005 18:36:06 -0000
*************** mstring;
*** 92,104 ****


  /* Flags to specify which standard/extension contains a feature.  */
! #define GFC_STD_GNU                (1<<5)    /* GNU Fortran extension.  */
! #define GFC_STD_F2003             (1<<4)    /* New in F2003.  */
  /* Note that no features were obsoleted nor deleted in F2003.  */
! #define GFC_STD_F95                 (1<<3)    /* New in F95.  */
! #define GFC_STD_F95_DEL         (1<<2)    /* Deleted in F95.  */
! #define GFC_STD_F95_OBS        (1<<1)    /* Obsoleted in F95.  */
! #define GFC_STD_F77                 (1<<0)    /* Up to and including F77.  */

  /*************************** Enums *****************************/

--- 92,105 ----


  /* Flags to specify which standard/extension contains a feature.  */
! #define GFC_STD_LEGACY		(1<<6) /* Backward compatability.  */
! #define GFC_STD_GNU		(1<<5)    /* GNU Fortran extension.  */
! #define GFC_STD_F2003		(1<<4)    /* New in F2003.  */
  /* Note that no features were obsoleted nor deleted in F2003.  */
! #define GFC_STD_F95		(1<<3)    /* New in F95.  */
! #define GFC_STD_F95_DEL		(1<<2)    /* Deleted in F95.  */
! #define GFC_STD_F95_OBS		(1<<1)    /* Obsoleted in F95.  */
! #define GFC_STD_F77		(1<<0)    /* Up to and including F77.  */

  /*************************** Enums *****************************/

Index: options.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/options.c,v
retrieving revision 1.19
diff -c -3 -p -r1.19 options.c
*** options.c	10 May 2005 22:06:43 -0000	1.19
--- options.c	28 May 2005 18:36:06 -0000
*************** gfc_init_options (unsigned int argc ATTR
*** 77,85 ****
    flag_errno_math = 0;

    gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
!     | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU;
    gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
!     | GFC_STD_F2003;

    gfc_option.warn_nonstd_intrinsics = 0;

--- 77,86 ----
    flag_errno_math = 0;

    gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
!     | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU
!     | GFC_STD_LEGACY;
    gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
!     | GFC_STD_F2003 | GFC_STD_LEGACY;

    gfc_option.warn_nonstd_intrinsics = 0;

*************** gfc_post_options (const char **pfilename
*** 113,118 ****
--- 114,122 ----
    /* If -pedantic, warn about the use of GNU extensions.  */
    if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
      gfc_option.warn_std |= GFC_STD_GNU;
+   /* -std=legacy -pendantic is effectively -std=gnu.  */
+   if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
+     gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;

    /* If the user didn't explicitly specify -f(no)-second-underscore we
       use it if we're trying to be compatible with f2c, and not
*************** gfc_handle_option (size_t scode, const c
*** 333,340 ****
      case OPT_std_gnu:
        gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
  	| GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
! 	| GFC_STD_GNU;
!       gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL;
        break;

      case OPT_Wnonstd_intrinsics:
--- 337,352 ----
      case OPT_std_gnu:
        gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
  	| GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
! 	| GFC_STD_GNU | GFC_STD_LEGACY;
!       gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
! 	| GFC_STD_LEGACY;
!       break;
!
!     case OPT_std_legacy:
!       gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
! 	| GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
! 	| GFC_STD_GNU | GFC_STD_LEGACY;
!       gfc_option.warn_std = 0;
        break;

      case OPT_Wnonstd_intrinsics:
Index: lang.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/lang.opt,v
retrieving revision 1.12
diff -c -3 -p -r1.12 lang.opt
*** lang.opt	10 May 2005 22:06:43 -0000	1.12
--- lang.opt	28 May 2005 18:36:06 -0000
*************** std=gnu
*** 161,164 ****
--- 161,168 ----
  F95
  Conform nothing in particular.

+ std=legacy
+ F95
+ Accept extensions to support legacy code.
+
  ; This comment is to ensure we retain the blank line above.
Index: invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/invoke.texi,v
retrieving revision 1.14
diff -c -3 -p -r1.14 invoke.texi
*** invoke.texi	10 May 2005 22:12:04 -0000	1.14
--- invoke.texi	28 May 2005 18:36:06 -0000
*************** Specify that no implicit typing is allow
*** 248,254 ****
  @cindex option, -std=@var{std}
  @item -std=@var{std}
  Conform to the specified standard.  Allowed values for @var{std} are
! @samp{gnu} and @samp{f95}.

  @end table

--- 248,254 ----
  @cindex option, -std=@var{std}
  @item -std=@var{std}
  Conform to the specified standard.  Allowed values for @var{std} are
! @samp{gnu}, @samp{f95}, @samp{f2003} and @samp{legacy}.

  @end table

Index: gfortran.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.texi,v
retrieving revision 1.13
diff -c -3 -p -r1.13 gfortran.texi
*** gfortran.texi	23 May 2005 03:20:19 -0000	1.13
--- gfortran.texi	28 May 2005 18:36:06 -0000
*************** Variable for swapping Endianness during
*** 618,624 ****

  @command{gfortran} implements a number of extensions over standard
  Fortran. This chapter contains information on their syntax and
! meaning.

  @menu
  * Old-style kind specifications::
--- 618,631 ----

  @command{gfortran} implements a number of extensions over standard
  Fortran. This chapter contains information on their syntax and
! meaning.  There are currently two categories of @command{gfortran}
! extensions, those that provide functionality beyond that provided
! by any standard, and those that are supported by @command{gfortran}
! purely for backward compatability with legacy compilers.  By default,
! @option{-std=gnu} allows the compiler to accept both types of
! extensions, but to warn about the use of the latter.  Specifying
! either @option{-std=f95} or @option{-std=f2003} disables both types
! of extensions, and @option{-std=legacy} allows both without warning.

  @menu
  * Old-style kind specifications::


Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]