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

            Bug ID: 84924
           Summary: Erroneous error in C_F_POINTER
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johnsonsr at ornl dot gov
  Target Milestone: ---

Created attachment 43691
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43691&action=edit
Module exemplifying failure

The gfortran compiler mistakenly prohibits calls to `c_f_pointer` where `fptr`
is a noninteroperable *scalar* derived type. The standard only prohibits this
for *arrays* of the derived type (and this restriction is lifted in TS29113).

The compiler correctly allows `c_loc(fptr)` on the same pointer object; and
according to the standard the ability to do `c_loc` and `c_f_pointer` should be
symmetric.

I have attached a minimal test case:
```
$ gfortran-mp-7 -save-temps -std=f2003 -c -Wall -Wextra ftest.f90
ftest.f90:27:38:

         call c_f_pointer(cptr=p, fptr=handle)
                                      1
Error: TS 29113/TS 18508: Noninteroperable array FPTR at (1) to C_F_POINTER:
Expression is a noninteroperable derived type
```

I think the code in `gfc_check_c_f_pointer` in `gcc/fortran/check.c` simply
needs to be replaced by similar code in `gfc_check_c_loc`:
```
if (!is_c_interoperable (fptr, &msg, false, true))
```
should become
```
if (fptr->rank > 0 && !is_c_interoperable (fptr, &msg, false, true))
```

Reply via email to