Length-parameterized passed object to type-bound procedure has gfortran complain
Asked Answered
F

3

7

I'm learning Fortran and I'd like to encapsulate an array and a subroutine in a type. The problem appears to be in the type definition of the self-object.

This is the minimal test case I came up with:

module testing
  implicit none

  type test(para)
    integer, len :: para
    real, dimension(para) :: weights

  contains
    procedure :: testing => testing_test
  end type
contains
  subroutine testing_test(self)
    class(test(*)) :: self
  end subroutine
end module

Compiling this with gfortran raises this error:

module_test.f08:9:23:

  procedure :: testing => testing_test
          1
Error: Argument ‘self’ of ‘testing_test’ with PASS(self) at (1) must be of the derived-type ‘test’

It works when the array-length is fixed (so type%para doesn't exist)

Is what I'm trying to do (type with array of variable size and bound procedure) plain impossible or am I missing something regarding dummy argument definition?

Fairfax answered 6/10, 2018 at 10:46 Comment(2)
It's probably a compiler bug. What version of gfortran are you using? PDT was included by gfortran recently, and there are still some bugs left.Maniemanifest
result of gfortran --version: GNU Fortran (GCC) 8.1.1 20180712 (Red Hat 8.1.1-5)Fairfax
F
6

Thanks to @Rodrigo for the idea, I finally found this bug (and patch): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82943

To fix the issue, download the source, apply the mentioned patch and compile your own gfortran. (Or wait until it's in the repositories)

Fairfax answered 6/10, 2018 at 20:13 Comment(0)
V
3

This is not really an answer but may provide a solution for some. gfortran-10 still has the same problem. However flang-7 compiles this example and it is available for Ubuntu since 19.10, and maybe other OS:es.

Vetiver answered 5/5, 2020 at 21:37 Comment(2)
There were so many flangs that this is a mess to me. Is this the "new flang" or the "old flang" from here fosdem.org/2020/schedule/event/llvm_flang/attachments/slides/… ?Rhoda
On packages.ubuntu.com/source/focal/flang it says "flang (20190329-5)" so should be "old" flang. But not sure.Cupola
B
1

A previous answer points to a bug report and patch for gfortran. It is worth saying, though, that this is standard Fortran (2003) code.

What we have here is a type-bound procedure with passed-object dummy argument. The main restrictions of such an argument are that it is a:

  • scalar,
  • nonallocatable,
  • nonpointer object,
  • with all length-type parameters assumed.

Further, as the type is extensible the passed-object dummy argument must be polymorphic.

For the example of the question, all of the conditions are met.

Bluebeard answered 7/10, 2018 at 19:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.