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

            Bug ID: 119272
           Summary: Function misidentified as non-function in associate
                    statement
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xingjingwei666 at gmail dot com
  Target Milestone: ---

Test case:

module test_module
   type, public :: test_type
      contains
      procedure :: test_function
   end type test_type
   contains
   function test_function(this) result(smth)
      class(test_type) :: this
      integer :: smth
      smth = 1
   end function
end module

program test
      use test_module
      implicit none
      contains
      subroutine test_subroutine(a)
            class(test_type) :: a
            integer :: temp_int(3)
            associate(temp => temp_int(a%test_function()))
            ! 'test_function' at (1) should be a FUNCTION
            end associate
      end subroutine
end program

When compiling the code without flag, compiler incorrectly reports that the
type-bounded procedure "test_function" is not a function, and gives the
following error message:

test.f90:22:39:

   22 |             associate(temp => temp_int(a%test_function()))
      |                                       1
Error: 'test_function' at (1) should be a FUNCTION

If use "type(test_type)" instead of "class(test_type)" in the declaration of
"test_subroutine", gfortran will compile successfully. If associate
"a%test_function()" directly instead of indexing, it will also compile
successfully.

It occurs on gfortran 14.2.0 and 13.3.0, but not on 12.4.0.

My platform is MacBook Pro(M4 pro). But I also test on WSL2(core i7 11700,
Ubuntu 24.04.1) and result is the same.

gfortran -v gives:                                                              
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/14.2.0_1/bin/../libexec/gcc/aarch64-apple-darwin24/14/lto-wrapper
Target: aarch64-apple-darwin24
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc
--libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls
--enable-checking=release --with-gcc-major-version-only
--enable-languages=c,c++,objc,obj-c++,fortran,m2 --program-suffix=-14
--with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr
--with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl
--with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 14.2.0_1'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--with-system-zlib --build=aarch64-apple-darwin24
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Homebrew GCC 14.2.0_1)

Reply via email to