This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran, OOP] PR 56261: seg fault call procedure pointer on polymorphic array


Am 10.04.2013 16:21, schrieb Janus Weil:
2013/4/7 Tobias Burnus <burnus@net-b.de>:
Thus, the only place where the check can be is for:

    f => ff

In your example, the explicit interface of "ff" is known thus it should
be
testable at resolution time of the proc-pointer assignment.
Right. However, strictly speaking, the pointer assignment as such is
probably valid. But of course there is not much one can do with the
proc-ptr afterwards, if it's invalid to call it ...
  Well, if one doesn't want to error on it, one can still warn. However, the
following states that it is invalid:

"If the characteristics of the pointer object or the pointer target are such
that an explicit interface is required, both the pointer object and the
pointer target shall have an explicit interface." (F2008, para 4 of "7.2.2.4
Procedure pointer assignment")
Ok, here is an updated patch, which does the discussed checking for
procedure pointer assignments. For this I have introduced a new
function 'gfc_explicit_interface_required', which checks all the items
in F08:12.4.2.2 and is loosely based on the present checks in
'resolve_global_procedure' (which are replaced by the new function).

I hope the general idea of the patch is ok and the error messages are
sufficiently comprehensible.

One leftover problem: The patch currently fails on the auto_char_len_4
test case, which is not being rejected any more. Actually I'm not
fully convinced that the dg-errors there are correct: If the EXTERNAL
statements in auto_char_len_{1,2} do not trigger an "explicit
interface required" warning, I don't see why the ones in
auto_char_len_4 should.

Regarding auto_char_len_[12].f90: A warning about an "explicit interface required" would be a bad joke as it contains an assumed character length function, which is a deprecated feature (cf. B.2.6) and it does *not* work with an explicit interface:

character(len=*) function func()
  func = 'ABC'
end function func

Question: Which length does the function result have? Answer, it depends on the declaration in the caller:
  character(len=2) :: func
  print *, func()
means that it has length 2. If you have len=4 in another procedures, it will have len=4 in that scoping unit.


By contrast, auto_char_len_4 uses "normal" function results, which could be used with an explicit interface.

As F2008 states ("12.4.2.2 Explicit interface"), an explicit interface is required if: "[...] (3) the procedure has a result that [...] (c) has a nonassumed type parameter value that is not a constant expression,"

The assumed-type-parameter is used in auto_char_len_{1,2}.f90.

In auto_char_len_4.f90: The example does not have anything to do with whole-file diagnostic; the problem is just that the characteristics do not match. (The functions itself use a constant length.) But if "len=n" also had been used in the functions, the error would be correct. Thus, I would like to keep such a diagnostic for external function declarations, which should trigger even if the called function is not in the same file. (One could move the warning to, e.g., resolve_variable.) Quote from *_4.f90:

SUBROUTINE s(n)
CHARACTER(LEN=n), EXTERNAL :: a ! { dg-error "must have an explicit interface" } CHARACTER(LEN=n), EXTERNAL :: d ! { dg-error "must have an explicit interface" }

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]