Bug 60751 - Extra comma in WRITE statement not diagnosed
Summary: Extra comma in WRITE statement not diagnosed
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 70575 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-04-03 17:30 UTC by Walter Spector
Modified: 2016-06-12 21:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-04-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Spector 2014-04-03 17:30:34 UTC

    
Comment 1 Walter Spector 2014-04-03 17:34:49 UTC
Simple test case:

program extracomma
  implicit none

  write (*,*), 1, 2, 3
end program

This compiles without error.

I notice that if I compile with -std=f95, it does diagnose this as a GNU Extension.  My thoughts are that a warning message should be issued, rather than quietly accepting the extension by default.
Comment 2 Harald Anlauf 2014-04-03 18:51:20 UTC
gfortran is quite in line with other compilers.  ifort is also quiet by default.
However,

% gfc-trunk prxxx.f90 -std=f2008
prxxx.f90:4.13:

  write (*,*), 1, 2, 3
             1
Error: GNU Extension: Comma before i/o item list at (1)

% ifort prxxx.f90 -stand f08
prxxx.f90(4): warning #5198: Use of comma to separate io-access spec and io_list is non_standard.
  write (*,*), 1, 2, 3
-------------^

So gfortran is even stricter than ifort.  Did you complain to Intel?
Comment 3 Walter Spector 2014-04-03 19:26:43 UTC
I didn't complain to Intel, but I can...

However the compilers that did catch it by default were NAG, lahey, and Absoft.

Walter
Comment 4 Dominique d'Humieres 2014-04-05 09:55:15 UTC
> My thoughts are that a warning message should be issued, rather than
> quietly accepting the extension by default.

It seems quite trivial to fix, but does it really worth the work?
Comment 5 Walter Spector 2014-04-05 15:03:08 UTC
> It seems quite trivial to fix, but does it really worth the work?

Well, we had an instance where this accidentally slipped into our code.  Later on, our nightly regression runs crashed with several non-gfortran (and non-Intel) compilers.

The extension itself is pretty gratuitous.  It adds nothing to the language, yet can quietly promote incompatibilities.  Since g95 also accepts it, I am assuming it came into the compiler before the split.
Comment 6 Walter Spector 2014-04-05 15:07:57 UTC
Adding that both READ and WRITE have this issue.  Interestingly, the iolength version of INQUIRE does not:

  inquire (iolength=i), i
                      1
Error: Expected expression in INQUIRE statement at (1)
Comment 7 Harald Anlauf 2014-04-05 15:13:26 UTC
(In reply to Walter Spector from comment #5)
> > It seems quite trivial to fix, but does it really worth the work?
> 
> Well, we had an instance where this accidentally slipped into our code. 
> Later on, our nightly regression runs crashed with several non-gfortran (and
> non-Intel) compilers.

If you want diagnostics of standard violations, you might consider adding -std=f2008 (e.g.) to the compile flags in your test suite.  Most compilers allow "their" set of extensions by default.

> The extension itself is pretty gratuitous.  It adds nothing to the language,
> yet can quietly promote incompatibilities.  Since g95 also accepts it, I am
> assuming it came into the compiler before the split.
Comment 8 kargls 2014-04-06 05:18:25 UTC
(In reply to Walter Spector from comment #6)
> Adding that both READ and WRITE have this issue.  Interestingly, the
> iolength version of INQUIRE does not:
> 
>   inquire (iolength=i), i
>                       1
> Error: Expected expression in INQUIRE statement at (1)

It a g77 compatibility issue.  From the g77 manual (page 190),

ยท The commas in `READ (5), I' and `WRITE (10), J'.
  These commas are disallowed by FORTRAN 77, but, while strictly superfluous,
  are syntactically elegant, especially given that commas are required in
  statements such as `READ 99, I' and `PRINT *, J'. Many compilers permit
  the superfluous commas for this reason.

This is part of GNU Fortran, which I agree a cesspool of vendor
extensions.  I doubt that this will be changed (too many more
important things to work on).  If you want strict conformance,
it is probably best to add -std=f95 or -std=f2003, or -std=2008
to your command line.
Comment 9 Walter Spector 2014-04-06 15:45:08 UTC
Harald and Steve: I am quite aware of the std= options, thanks.

My main point is that the default situation violates the Principle of Least Astonishment.  I don't have a problem with gfortran offering such an extension (though I think providing it in the first place was a waste of time).  But since it offers no desireable new capability, and allows gratuitous incompatibility with other compilers, it would at least be worth a warning.  The ideal would be to only allow it under a -f option - but don't do that on my account.

In fact the gfortran man page for the -std= argument states:

           "...The default
           value for std is gnu, which specifies a superset of the Fortran 95
           standard that includes all of the extensions supported by GNU
           Fortran, although warnings will be given for obsolete extensions
           not recommended for use in new code..."

I would opine that this extension is obsolete and not recommeded for use in new code.  Therefore a warning should be given.
Comment 10 Steve Kargl 2014-04-06 16:52:49 UTC
On Sun, Apr 06, 2014 at 03:45:08PM +0000, w6ws at earthlink dot net wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60751
> 
> --- Comment #9 from Walter Spector <w6ws at earthlink dot net> ---
> Harald and Steve: I am quite aware of the std= options, thanks.
> 
> My main point is that the default situation violates the Principle of Least
> Astonishment.

And my point is that the feature/bug is there solely for
backwards compatibility with g77.  A POLA issue back when
gfortran first replaced g77 in GCC.  Just last week in
c.l.f there was a long thread from someone who could not
use gfortran to build his legacy code, because gfortran
does not support a number of g77's old -fugly-* options.

In hindsight, I now regret contributing a number of patches
to implement g77 compatibility and common vendor extensions.
In fact, I think the default should be -std=f95+f2003+f2008.
If the feature isn't in one of the standards, an error should
be issued without an explicit option to permit the feature.
Unfortrunately, the horse left the barn years ago.
Comment 11 Jerry DeLisle 2014-04-07 03:13:01 UTC
We could just change this to a -std=legacy or a warning that would not appear with -w.
Comment 12 Dominique d'Humieres 2014-12-06 22:20:58 UTC
Is there an agreement to downgrade the error from GFC_STD_GNU in

gcc/fortran/io.c:      && !gfc_notify_std (GFC_STD_GNU, "Comma before i/o item list at %L", 

to GFC_STD_LEGACY? If yes, I'll submit a patch. If not, this PR should be closed as WONTFIX.
Comment 13 Dominique d'Humieres 2015-08-30 10:23:00 UTC
> Is there an agreement to downgrade the error from GFC_STD_GNU in
>
> gcc/fortran/io.c:      && !gfc_notify_std (GFC_STD_GNU, "Comma before i/o
> item list at %L", 
>
> to GFC_STD_LEGACY? If yes, I'll submit a patch. If not, this PR should be
> closed as WONTFIX.

PING! Without answer, I'll close the PR as WONTFIX.
Comment 14 Walter Spector 2015-08-30 14:39:16 UTC
Hi Dominique,

I am sorry I didn't see or respond to your comment from last year.  Thank you for the ping.

Yes, it would be fine with me to recategorize the error as GFC_STD_LEGACY.

Walter
Comment 15 Dominique d'Humieres 2015-08-30 15:25:25 UTC
> Yes, it would be fine with me to recategorize the error as GFC_STD_LEGACY.

Thanks for the answer, but the ping was intended to the gfortran maintainers (I knew your answer). If there is no objection in the coming week, I'll commit the change under the obvious rule.
Comment 16 Dominique d'Humieres 2016-04-07 16:26:35 UTC
*** Bug 70575 has been marked as a duplicate of this bug. ***
Comment 17 Dominique d'Humieres 2016-04-07 21:12:04 UTC
Note that the extra comma is used in the following tests:

gfortran.dg/array_constructor_49.f90
gfortran.dg/integer_exponentiation_6.F90
gfortran.dg/graphite/pr38083.f90

Any reason to keep it?
Comment 18 Jerry DeLisle 2016-04-10 23:53:23 UTC
(In reply to Dominique d'Humieres from comment #17)
> Note that the extra comma is used in the following tests:
> 
> gfortran.dg/array_constructor_49.f90
> gfortran.dg/integer_exponentiation_6.F90
> gfortran.dg/graphite/pr38083.f90
> 
> Any reason to keep it?

No, and I am planning to fix the diagnostic on this.
Comment 19 dominiq 2016-06-11 19:20:15 UTC
Author: dominiq
Date: Sat Jun 11 19:19:43 2016
New Revision: 237329

URL: https://gcc.gnu.org/viewcvs?rev=237329&root=gcc&view=rev
Log:
2016-06-11  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/60751
	* io.c (gfc_resolve_dt): Replace GFC_STD_GNU with GFC_STD_LEGACY.

	* gfortran.dg/comma_IO_extension_1.f90: New test.
	* gfortran.dg/comma_IO_extension_2.f90: Likewise.
	* gfortran.dg/array_constructor_49.f90: Remove extra comma in WRITE
	statement.
	* gfortran.dg/graphite/pr38083.f90: Likewise.
	* gfortran.dg/integer_exponentiation_6.F90: Likewise and add
	missing format.

--This line

M    fortran/ChangeLog
M    fortran/io.c
M    testsuite/ChangeLog
M    testsuite/gfortran.dg/array_constructor_49.f90
M    testsuite/gfortran.dg/graphite/pr38083.f90
M    testsuite/gfortran.dg/integer_exponentiation_6.F90

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/io.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/array_constructor_49.f90
    trunk/gcc/testsuite/gfortran.dg/graphite/pr38083.f90
    trunk/gcc/testsuite/gfortran.dg/integer_exponentiation_6.F90
Comment 20 dominiq 2016-06-11 19:21:54 UTC
Author: dominiq
Date: Sat Jun 11 19:21:22 2016
New Revision: 237330

URL: https://gcc.gnu.org/viewcvs?rev=237330&root=gcc&view=rev
Log:
2016-06-11  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR target/60751
	* gfortran.dg/comma_IO_extension_1.f90: New test.
	* gfortran.dg/comma_IO_extension_2.f90: Likewise.


Added:
    trunk/gcc/testsuite/gfortran.dg/comma_IO_extension_1.f90
    trunk/gcc/testsuite/gfortran.dg/comma_IO_extension_2.f90
Comment 21 dominiq 2016-06-11 22:37:22 UTC
Author: dominiq
Date: Sat Jun 11 22:36:50 2016
New Revision: 237332

URL: https://gcc.gnu.org/viewcvs?rev=237332&root=gcc&view=rev
Log:
2016-06-12  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR target/60751
	* gfortran.dg/guality/pr41558.f90: Remove extra comma in WRITE
	statement.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/guality/pr41558.f90
Comment 22 dominiq 2016-06-12 14:04:40 UTC
Author: dominiq
Date: Sun Jun 12 14:04:08 2016
New Revision: 237337

URL: https://gcc.gnu.org/viewcvs?rev=237337&root=gcc&view=rev
Log:
2016-06-12  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/60751
	* io.c (gfc_resolve_dt): Replace GFC_STD_GNU with GFC_STD_LEGACY.

	* gfortran.dg/comma_IO_extension_1.f90: New test.
	* gfortran.dg/comma_IO_extension_2.f90: Likewise.
	* gfortran.dg/array_constructor_49.f90: Remove extra comma in WRITE
	statement.
	* gfortran.dg/graphite/pr38083.f90: Likewise.
	* gfortran.dg/guality/pr41558.f90: Likewise.
	* gfortran.dg/integer_exponentiation_6.F90: Likewise and add
	missing format.


Added:
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/comma_IO_extension_1.f90
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/comma_IO_extension_2.f90
Modified:
    branches/gcc-6-branch/gcc/fortran/ChangeLog
    branches/gcc-6-branch/gcc/fortran/io.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/array_constructor_49.f90
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/graphite/pr38083.f90
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/guality/pr41558.f90
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/integer_exponentiation_6.F90
Comment 23 dominiq 2016-06-12 18:25:57 UTC
Author: dominiq
Date: Sun Jun 12 18:25:25 2016
New Revision: 237340

URL: https://gcc.gnu.org/viewcvs?rev=237340&root=gcc&view=rev
Log:
2016-06-12  Dominique d'Humieres  <dominiq@lps.ens.fr>

	PR fortran/60751
	* io.c (gfc_resolve_dt): Replace GFC_STD_GNU with GFC_STD_LEGACY.

	* gfortran.dg/comma_IO_extension_1.f90: New test.
	* gfortran.dg/comma_IO_extension_2.f90: Likewise.
	* gfortran.dg/array_constructor_49.f90: Remove extra comma in WRITE
	statement.
	* gfortran.dg/graphite/pr38083.f90: Likewise.
	* gfortran.dg/guality/pr41558.f90: Likewise.
	* gfortran.dg/integer_exponentiation_6.F90: Likewise and add
	missing format.


Added:
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/comma_IO_extension_1.f90
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/comma_IO_extension_2.f90
Modified:
    branches/gcc-5-branch/gcc/fortran/ChangeLog
    branches/gcc-5-branch/gcc/fortran/io.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/array_constructor_49.f90
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/graphite/pr38083.f90
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/guality/pr41558.f90
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/integer_exponentiation_6.F90
Comment 24 Dominique d'Humieres 2016-06-12 18:33:50 UTC
Fixed on trunk and the gcc-5 and 6 branches. Thanks for the report. Closing.
Comment 25 Walter Spector 2016-06-12 21:06:56 UTC
Thank you Dominique!

Walter