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/52111] [OOP] procedure pointer with polymorphic passed dummy argument
Date: Fri, 03 Feb 2012 17:32:00 -0000	[thread overview]
Message-ID: <bug-52111-4-WjD9McDAfh@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-52111-4@http.gcc.gnu.org/bugzilla/>

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

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

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-03 17:31:45 UTC ---
I think gfortran correctly rejects your code.

You cannot have a procedure pointer, which takes according to the interface a
CLASS(solverAbstract_t) as first argument - and then associate it to a
procedure which takes only a CLASS(solver_t) as argument.

Assume, I declare a another type "my_t", which also extends solverAbstract_t.
If I now do:

 class(solver_t):: this
 type(my_t) :: x
 this%solve => solveLeft_sub
 call this%solve (x, 5)

everything is fine according to the standard: this%solve takes as first
argument CLASS(solverAbstract_t) and TYPE(my_t) is conforming to that. However,
"solveLeft_sub" has a problem because it neither expects a "solverAbstract_t"
nor a "my_t" but only "solver_t" or types which are extending "solver_t".

If one does not want to go back to F77 where one blindly passes arguments as
there is no argument checking, the compiler has to have a chance to detect the
problem. As it cannot do it for the call, it has to do it for the proc-pointer
assignment. Which gfortran does.

Thus, "solveLeft_sub" has to also accept CLASS(solverAbstract_t). It might then
do:
  select type (this)
    class is (solver_t):
      ! do something
    class default
      error stop "should never happen"
  end select



>From the Fortran 2008 standard (cf. http://gcc.gnu.org/wiki/GFortranStandards):

"7.2.2.4 Procedure pointer assignment"
"If the pointer object has an explicit interface, its characteristics shall be
the same as the pointer target except that the pointer target may be pure even
if the pointer object is not pure and the pointer target may be an elemental
intrinsic procedure even if the pointer object is not elemental."

And "12.3.2.2 Characteristics of dummy data objects":
"The characteristics of a dummy data object are its type, [...]"



Thus, I think the bug is in your program and not in gfortran. However, if you
can find something in the Fortran standard which states otherwise, I am happy
to reconsider my conclusion.

Note that the characteristics have to be the same is not stated via a
constraint in the standard. Thus, the compiler is not required to diagnose it -
and, seemingly, the Cray compiler doesn't.


  parent reply	other threads:[~2012-02-03 17:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-03 16:21 [Bug fortran/52111] New: " nagl46 at web dot de
2012-02-03 16:22 ` [Bug fortran/52111] " nagl46 at web dot de
2012-02-03 17:32 ` burnus at gcc dot gnu.org [this message]
2012-02-03 17:52 ` nagl46 at web dot de
2012-02-04 11:03 ` nagl46 at web dot de
2012-02-05 16:43 ` burnus at gcc dot gnu.org

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-52111-4-WjD9McDAfh@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).