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

            Bug ID: 101577
           Summary: [Interop] TYPE with BIND(C): Reject empty TYPE with
                    zero components
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: sandra at gcc dot gnu.org
  Target Milestone: ---

Fortran 2018 has:
  C1805 (R726) A derived type with the BIND attribute shall have at least one
component.

And:
"The effect of such a constraint ... that a processor is required to have the
capability to detect and report violations of constraints"

Hence, I'd expect an error when using the following with -std=f2018 (and
f95/f2003/f2008):

 type,bind(C) :: t
 end type t
 end

However, gfortran currently only shows the warning:

  Warning: Derived type ‘t’ with BIND(C) attribute at (1) is empty, and may be
inaccessible by the C companion processor

 * * *

Note that the explicit constraint is new in Fortran 2018 – before it only
rejects this indirectly by referencing to the ISO C standard (which disallows
empty struct). But I do note that an empty struct is a common vendor extension.

 * * *

The issue came up at
https://mailman.j3-fortran.org/pipermail/j3/2021-July/013190.html
and the C reference which disallows size-zero structs is:
  6.7.2.1 of C 2018

As GCC supports empty structs, we could consider skipping the warning with
-std=gnu – or we keep it in the 'else' branch. In any case, there should be a
  gfc_notify_std (GFC_STD_GNU, ...
diagnostic in the 'if' branch.

Reply via email to