Bug 25062 - same name for parameter and common block
Summary: same name for parameter and common block
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Tobias Burnus
URL:
Keywords: accepts-invalid
: 50072 (view as bug list)
Depends on:
Blocks: 32515
  Show dependency treegraph
 
Reported: 2005-11-26 17:50 UTC by Joost VandeVondele
Modified: 2011-08-13 11:21 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-06-26 16:21:47


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2005-11-26 17:50:18 UTC
using GNU Fortran 95 (GCC) 4.1.0 20051126 (prerelease)  with '-g -pedantic -std=f95', I get a bad / no diagnostic for the following invalid code:

INTEGER, PARAMETER ::  C1=1
COMMON /C1/ I
INTEGER I
END
Comment 1 Francois-Xavier Coudert 2005-11-26 19:41:47 UTC
Well, only g95 sees this bug. Is it really a violation of the standard? I don't think so...

## g95 ##
In file foo.f90:1

INTEGER, PARAMETER ::  C1=1
                         1
Error: COMMON block 'c1' at (1) is also a PARAMETER
## Intel ##
## Portland ##
## Sun ##
Comment 2 Tobias Schlüter 2006-01-11 14:29:02 UTC
I'm quite sure it's not, but it would be a first, if Joost were wrong.  Is there anything special about parameters?  Something like
   real x
   common /x/ y
or even
   common /x/ x
is perfectly valid.
Comment 3 Andrew Pinski 2006-01-11 14:32:27 UTC
Even Lahey's Fortran 90 and their 95 compiler does not error out about this.

I wonder if xlf does.
Comment 4 Joost VandeVondele 2006-01-11 15:57:19 UTC
(In reply to comment #3)
> Even Lahey's Fortran 90 and their 95 compiler does not error out about this.
> 
> I wonder if xlf does.
> 

xlf90 -qsuffix=f=f90 mytest.f90
"mytest.f90", line 2.9: 1514-259 (S) A name must not be both the name of a named constant and the name of a COMMON block.
Comment 5 Andrew Pinski 2006-01-11 23:46:46 UTC
Confirmed then.  I would expect for some reason that xlf is actually one of the better fortran compilers when it comes to rejecting invalid code.
Comment 6 Tobias Schlüter 2006-01-12 00:18:17 UTC
I'm setting this to waiting until someone quotes something from the standard. 

Fortran has its quirks, but disallowing this special case would break the distintion between the names of commons and those of other named objects, which is otherwise maintained, so I'm sure this is valid code.  But since being sure is not sufficient, I also checked the standard and I couldn't find anything disallowing this case.
Comment 7 kargls 2006-01-12 05:25:44 UTC
See 14.1.2.1.
   A common block name in a scoping unit also may be the name of any local
   entity other than a named constant, intrinsic procedure, or a local variable
   that is also an external function in a function subprogram.
Comment 8 Tobias Schlüter 2006-01-12 10:13:46 UTC
Thanks, Steve.
Comment 9 patchapp@dberlin.org 2007-06-26 16:25:14 UTC
Subject: Bug number PR 25062

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-06/msg01932.html
Comment 10 Tobias Burnus 2007-07-03 21:41:45 UTC
Subject: Bug 25062

Author: burnus
Date: Tue Jul  3 21:41:34 2007
New Revision: 126279

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126279
Log:
2007-07-03  Tobias Burnus  <burnus@net-b.de>

	PR fortran/25062
	* resolve.c (resolve_common_blocks): New check function.
	(resolve_types): Use it.

2007-07-03  Tobias Burnus  <burnus@net-b.de>

	PR fortran/25062
	* common_7.f90: New.
	* common_8.f90: New.
	* common_9.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/common_7.f90
    trunk/gcc/testsuite/gfortran.dg/common_8.f90
    trunk/gcc/testsuite/gfortran.dg/common_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 11 Tobias Burnus 2007-07-03 21:45:47 UTC
Fixed. Note that the F95 standard is stricter than F2003. I added one -std=95 only check and two general checks. Still gfortran is too strict for F2003; see PR32515.
Comment 12 Dominique d'Humieres 2011-08-13 11:21:34 UTC
*** Bug 50072 has been marked as a duplicate of this bug. ***