public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/54082] Program name shadows other entities with the same name
Date: Tue, 24 Jul 2012 15:43:00 -0000	[thread overview]
Message-ID: <bug-54082-4-iQ425eullo@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-54082-4@http.gcc.gnu.org/bugzilla/>

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.


  reply	other threads:[~2012-07-24 15:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24 12:50 [Bug fortran/54082] New: " tob.brandt at googlemail dot com
2012-07-24 15:43 ` burnus at gcc dot gnu.org [this message]
2012-07-24 15:53 ` [Bug fortran/54082] " burnus at gcc dot gnu.org
2015-10-13 16:42 ` dominiq at lps dot ens.fr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-54082-4-iQ425eullo@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).