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

            Bug ID: 115151
           Summary: procedure(acos) [,pointer] :: p  - is wrongly rejected
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

IT looks as if the following is wrongly rejected:

procedure(acos) [,pointer] :: p

While the examples below are with 'pointer', I don't see why it shouldn't be
also valid without 'pointer', but I have not verified it.

But I have to admit that I also have not fully understood C1218 – as I don't
see how one could ever specify something else - it either is by construction an
external procedure or it clashes name wise.

Only:
  procedure(acos)[,pointer] :: acos
does not make sense as the former pulls in an 'intrinsic :: acos'.

* * *

Found at https://github.com/klausler/fortran-wringer-tests/ which has several
corner case testcases.

Testcase: acos-iface.f90
-------------
! Intel, NVF, NAG, f18: works
! GNU, XLF: errors about elemental or non-external procedure as interface
intrinsic :: acos
procedure(acos), pointer :: p
p => acos
print *, p(1.)
end
-------------

gfortran:
   Error: Procedure pointer 'p' at (1) shall not be elemental

GCC's source code refers for this to F2008's ("15.4.3.6 Procedure declaration
statement"):

"C1218 (R1211) If a proc-interface describes an elemental procedure, each
procedure-entity-name shall specify an external procedure."

where

R1211 procedure-declaration-stmt is PROCEDURE ( [ proc-interface ] )7
[ [ , proc-attr-spec ] ... :: ] proc-decl -list

R1214 proc-decl is procedure-entity-name [ => proc-pointer-init ]

* * *

Furthermore, for procedure pointers, there is:

C1220 (R1217) The procedure-name shall be the name of a nonelemental external
or module procedure, or a specific intrinsic function listed in 13.6 and not
marked with a bullet (•).

where:
"R1216 proc-pointer-init is null-init
                         or initial-proc-target
 R1217 initial-proc-target is procedure-name"

'acos' has no dot – and 13.6 has:

"Note that a specific function that is marked with a bullet (•) is not
permitted to be used as an actual argument (12.5.1, C1220), as a target in a
procedure pointer assignment statement (7.2.2.2, C729), or as the interface in
a procedure declaration statement (12.4.3.6, C1216)."

The latter implies that 'acos' is permitted on 'p => acos'.

* * *

Thus, the question is still whether  C1218   makes sense for 'p', i.e. does it
apply to 'p' and (if so) is this is valid for proc pointers or not?

"C855 A named procedure with the POINTER attribute shall have the EXTERNAL
attribute."  is in any case required for proc-pointers as well.

However, that's given by:
"A procedure declaration statement declares procedure pointers, dummy
procedures, and external procedures. It specifies the EXTERNAL attribute
(8.5.9) for all entities in the proc-decl-list."

Which means - unsurprisingly - that the following is invalid:

module m
contains
 subroutine msub; end;
end

use m
intrinsic :: acos
pointer :: msub, intsub, acos   ! INVALID
contains
subroutine intsub; end
end

Reply via email to