public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/54082] New: Program name shadows other entities with the same name
@ 2012-07-24 12:50 tob.brandt at googlemail dot com
  2012-07-24 15:43 ` [Bug fortran/54082] " burnus at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: tob.brandt at googlemail dot com @ 2012-07-24 12:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54082

             Bug #: 54082
           Summary: Program name shadows other entities with the same name
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tob.brandt@googlemail.com


If the name of a program is the same as the name of another
entity (e.g. a function), that entity can not be used in
the program.

---

Example:

program abs
  print *, abs(-1)
end program

Compiling above program fails with this confusing error:

  print *, abs(-1)
              1
Error: Symbol at (1) is not appropriate for an expression

---

I'm not sure if the program is standard conform or not.
If it isn't, then the error message could be improved.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/54082] Program name shadows other entities with the same name
  2012-07-24 12:50 [Bug fortran/54082] New: Program name shadows other entities with the same name tob.brandt at googlemail dot com
@ 2012-07-24 15:43 ` burnus at gcc dot gnu.org
  2012-07-24 15:53 ` burnus at gcc dot gnu.org
  2015-10-13 16:42 ` dominiq at lps dot ens.fr
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-07-24 15:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54082

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-07-24 15:43:11 UTC ---
(In reply to comment #0)
> program abs
>   print *, abs(-1)
> end program

That program is invalid.


The compiler knows in the first line only that "abs" is the name of the PROGRAM
- if you then use it as function, it rightly complains.

Note that "abs" is no reserved name, you could also have the following (which
is valid):

program test
  call abs ()
contains
  subroutine abs ()
  end subroutine abs
end program test

In that case, "abs" is a subroutine - and not the intrinsic function "abs".


gfortran gives a better error message if you tell it explicitly that you want
to use "abs" as intrinsic procedure:

program abs
  intrinsic abs
  ...

Then it prints:
  intrinsic abs
               1
Error: PROGRAM attribute conflicts with INTRINSIC attribute at (1)

Otherwise, it has to guess that from the usage - as long the name is not
explicitly used elsewhere. Like in my valid "subroutine abs" example or your
invalid "program abs".


Back to your example, and quoting from the Fortran standard (cf.
http://gcc.gnu.org/wiki/GFortranStandards; F2008, Section 16.2):

"Program units, common blocks, external procedures, entities with binding
labels, external input/output units, pending data transfer operations, and
images are global entities of a program. [...]"

"The global identifier of an entity shall not be the same as the global
identifier of any other entity."

Here, "program abs" is a "program unit" and the function "abs" of "abs(-1)" is
an "external procedure".


(For completeness: As used in my example, the "abs" subroutine is a local
identifier, which per 16.3.1 "shall not be the same as a global identifier
used in that scope unless [...]" - thus, I used a different name, i.e "test".)


> Compiling above program fails with this confusing error:
>   print *, abs(-1)
>               1
> Error: Symbol at (1) is not appropriate for an expression
> 
> I'm not sure if the program is standard conform or not.
> If it isn't, then the error message could be improved.


Well, there ways to write invalid programs are legion; the compiler should try
to provide a good error message, but that's not always simple. (And the
development currently focuses on correctly implementing the missing features of
Fortran 2003 and 2008.) Nonetheless, providing good diagnostics is a goal.

ifort has: "This global name is invalid in this context.   [ABS]"
NAG has: "Invalid recursive self-reference to ABS"
pathf95 has: "This reference to main program ABS is illegal."

I am not sure that those are better.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/54082] Program name shadows other entities with the same name
  2012-07-24 12:50 [Bug fortran/54082] New: Program name shadows other entities with the same name tob.brandt at googlemail dot com
  2012-07-24 15:43 ` [Bug fortran/54082] " burnus at gcc dot gnu.org
@ 2012-07-24 15:53 ` burnus at gcc dot gnu.org
  2015-10-13 16:42 ` dominiq at lps dot ens.fr
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-07-24 15:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54082

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-07-24 15:53:20 UTC ---
(In reply to comment #1)
> (In reply to comment #0)
> > program abs
> >   print *, abs(-1)
> > end program

> Back to your example, and quoting from the Fortran standard (cf.
> http://gcc.gnu.org/wiki/GFortranStandards; F2008, Section 16.2):
> 
> "Program units, common blocks, external procedures, entities with binding
> labels, external input/output units, pending data transfer operations, and
> images are global entities of a program. [...]"
> 
> "The global identifier of an entity shall not be the same as the global
> identifier of any other entity."
> 
> Here, "program abs" is a "program unit" and the function "abs" of "abs(-1)" is
> an "external procedure".


Actually, if you meant the intrinsic "abs" function, that the "abs" in
"abs(-1)" is not an "external procedure" and, thus, that "abs" is not a global
name. But a local identifier

"Identifiers of entities in the classes
 (1) [...] intrinsic procedures, [...]
are local identifiers."

Nonetheless, it is invalid as:

> As used in my example, the "abs" subroutine is a local
> identifier, which per 16.3.1 "shall not be the same as a global identifier
> used in that scope unless [...]" - thus, I used a different name, i.e "test".)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug fortran/54082] Program name shadows other entities with the same name
  2012-07-24 12:50 [Bug fortran/54082] New: Program name shadows other entities with the same name tob.brandt at googlemail dot com
  2012-07-24 15:43 ` [Bug fortran/54082] " burnus at gcc dot gnu.org
  2012-07-24 15:53 ` burnus at gcc dot gnu.org
@ 2015-10-13 16:42 ` dominiq at lps dot ens.fr
  2 siblings, 0 replies; 4+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-10-13 16:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54082

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #3 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
As said by Tobias, the code is invalid and, although the error message could be
improved, nobody tried to do it during the past three years. IMO it is more
realistic to close this PR as WONTFIX rather to let it rot for the next decade.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-13 16:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-24 12:50 [Bug fortran/54082] New: Program name shadows other entities with the same name tob.brandt at googlemail dot com
2012-07-24 15:43 ` [Bug fortran/54082] " burnus at gcc dot gnu.org
2012-07-24 15:53 ` burnus at gcc dot gnu.org
2015-10-13 16:42 ` dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).