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

            Bug ID: 100870
           Summary: Constant expression for bind(C) name in interface body
                    not importable
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ehlert at thch dot uni-bonn.de
  Target Milestone: ---

Created attachment 50906
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50906&action=edit
Minimal reproducer

Following example fails to compile with GFortran 10.2.0. The example was
checked with Intel's and NAG's Fortran compiler, which both accept the usage of
constant expressions imported into an interface body as valid Fortran code.
>From the Fortran standard this usage is valid Fortran 2003.


Code example to trigger the bug (also in os.f90 attachment):

module m_os
  use, intrinsic :: iso_c_binding
  implicit none
  character(len=*), parameter :: chdir_symbol = "chdir"

  interface
    function chdir(path) result(stat) bind(C, name=chdir_symbol)
      import :: c_char, c_int, chdir_symbol
      character(kind=c_char, len=1), intent(in) :: path(*)
      integer(c_int) :: stat
    end function chdir
  end interface
end module m_os


Output showing GFortran rejecting this code with an error

❯ gfortran -v -save-temps -Wall -Wextra -fno-strict-aliasing -fwrapv -c os.f90
Using built-in specs.
COLLECT_GCC=gfortran
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-fno-strict-aliasing'
'-fwrapv' '-c' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/f951 os.f90 -quiet -dumpbase os.f90
-mtune=generic -march=x86-64 -auxbase os -Wall -Wextra -version
-fno-strict-aliasing -fwrapv -fintrinsic-modules-path
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/finclude
-fpre-include=/usr/include/finclude/math-vector-fortran.h -o os.s
GNU Fortran (GCC) version 10.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 10.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.21-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 10.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 10.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.21-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
os.f90:7:51:

    7 |     function chdir(path) result(stat) bind(C, name=chdir_symbol)
      |                                                   1
Error: Parameter ‘chdir_symbol’ at (1) has not been declared or is a variable,
which does not reduce to a constant expression
os.f90:8:13:

    8 |       import :: c_char, c_int, chdir_symbol
      |             1
Error: IMPORT statement at (1) only permitted in an INTERFACE body
os.f90:9:21:

    9 |       character(kind=c_char, len=1), intent(in) :: path(*)
      |                     1
Error: Parameter ‘c_char’ at (1) has not been declared or is a variable, which
does not reduce to a constant expression
os.f90:10:14:

   10 |       integer(c_int) :: stat
      |              1
Error: Parameter ‘c_int’ at (1) has not been declared or is a variable, which
does not reduce to a constant expression
os.f90:11:7:

   11 |     end function chdir
      |       1
Error: Expecting END INTERFACE statement at (1)
  • [Bug fortran/100870] New: Cons... ehlert at thch dot uni-bonn.de via Gcc-bugs

Reply via email to