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

            Bug ID: 127755
           Summary: Bogus compile errors for correct use of an EVENT_TYPE
                    pointer component
           Product: gcc
           Version: 16.2.0
               URL: https://docs.google.com/document/d/1OoRq_b-Anv9YIEyFPv
                    G1HZ7tALRM2ceY4h7UdCcQBJU/edit?tab=t.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dobonachea at lbl dot gov
  Target Milestone: ---

Created attachment 65767
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65767&action=edit
Test demonstrating correct use of an EVENT_TYPE pointer component

GFortran 16.2.0 on Linux/X64 is issuing bogus errors for the attached program,
which I believe fully conforms to the Fortran 2023 standard. The program works
as expected with Intel ifx 2026.1.1. 

Here are the relevant F2023 16.10.2.10 constraints for EVENT_TYPE:

> C1603 A named entity with declared type EVENT_TYPE, or which has a noncoarray 
> potential subobject
> component with declared type EVENT_TYPE, shall be a variable. A component 
> that is of such a type
> shall be a data component.
> 
> C1604 A named variable with declared type EVENT_TYPE shall be a coarray. A 
> named variable with a
> noncoarray potential subobject component of type EVENT_TYPE shall be a 
> coarray.
> 
> C1605 An event variable shall not appear in a variable definition context 
> except as the event-variable in an
> EVENT POST or EVENTWAIT statement, as an allocate-object, or as an actual 
> argument in a reference
> to a procedure with an explicit interface if the corresponding dummy argument 
> has INTENT (INOUT).
> 
> C1606 A variable with a nonpointer subobject of type EVENT_TYPE shall not 
> appear in a variable definition
> context except as an allocate-object in an ALLOCATE statement without a 
> SOURCE= specifier, as an
> allocate-object in a DEALLOCATE statement, or as an actual argument in a 
> reference to a procedure
> with an explicit interface if the corresponding dummy argument has INTENT 
> (INOUT).

FWIW, here is a standards conformance analysis for this test program generated
using Google Gemini, which I believe is accurate:
https://docs.google.com/document/d/1OoRq_b-Anv9YIEyFPvG1HZ7tALRM2ceY4h7UdCcQBJU/edit?tab=t.0

GFortran Demonstration:
---------------------------------------------------------

cgpu$ gfortran --version
GNU Fortran (GCC) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cgpu$ cat event_test5.F90
program event_test
  use iso_fortran_env, only: event_type
  implicit none

  type :: event_ptr
    type(event_type), pointer :: p
  end type

  type(event_type), target  :: data_ready[*]
  type(event_ptr) :: foo[*]

  foo%p => data_ready

  event post(foo[this_image()]%p)
  event post(foo%p)
  event wait(foo%p, UNTIL_COUNT=2)
  print *, this_image(), "success"
end program

cgpu$ gfortran -fcoarray=lib event_test5.F90 -lcaf_shmem && ./a.out
event_test5.F90:6:34:

    6 |     type(event_type), pointer :: p
      |                                  1
Error: Component p at (1) of type EVENT_TYPE must have a codimension or be a
subcomponent of a coarray, which is not possible as the component has the
pointer attribute
event_test5.F90:12:3:

   12 |   foo%p => data_ready
      |   1~~~~
Error: LOCK_EVENT in variable definition context (pointer assignment) at (1)
event_test5.F90:15:13:

   15 |   event post(foo%p)
      |             1
Error: Event variable argument at (1) must be a coarray or coindexed
event_test5.F90:16:13:

   16 |   event wait(foo%p, UNTIL_COUNT=2)
      |             1
Error: Event variable argument at (1) must be a coarray but not coindexed

---------------------------------------------------------

Every one of these compiler errors from GFortran is wrong:

1. "Error: Component p at (1) of type EVENT_TYPE must have a codimension or be
a subcomponent of a coarray"

There is no such requirement in the standard. 
This appears to be referring to C1604, but it does not apply to a pointer
component (which is not a potential subobject component).

2. "   12 |   foo%p => data_ready"
   "Error: LOCK_EVENT in variable definition context (pointer assignment) at "

There is no "LOCK" here, I assume "LOCK_EVENT" is a typo for "EVENT_TYPE".

However pointer assignment is a pointer association context (F2023 19.6.8) not
a variable definition context (F2023 19.6.7), therefore C1605/C1606 do not
apply.

3. "15 |   event post(foo%p)"
   "Error: Event variable argument at (1) must be a coarray or coindexed"

There is no such requirement in the standard. See 11.7.7 EVENT POST statement:

> R1174 event-post-stmt is EVENT POST ( event-variable [ , sync-stat-list ] )
> R1175 event-variable is scalar-variable
> C1183 (R1175) An event-variable shall be of type EVENT_TYPE from the 
> intrinsic module ISO_FORTRAN_ENV (16.10.2).
The event-variable is only required to be a scalar variable of type EVENT_TYPE.

4. "event wait(foo%p, UNTIL_COUNT=2)"
   "Error: Event variable argument at (1) must be a coarray but not coindexed"

There is no such requirement in the standard. See 11.7.8 EVENT WAIT statement:

> R1176 event-wait-stmt is EVENT WAIT ( event-variable [ , event-wait-spec-list 
> ] )
> C1184 (R1176) The event-variable in an event-wait-stmt shall not be coindexed.
The event-variable is only required to be a noncoindexed scalar variable of
type EVENT_TYPE.

Reply via email to