No default initialization for constant constructor

I have this test code, which should be compiled with nvfortran 24.11:

module m

  implicit none
  private

  type :: foo_t
     integer :: x = 0
  contains
    procedure :: do_stuff
  end type foo_t

  type(foo_t), parameter :: this_foo = foo_t(0)

  interface
    module subroutine do_stuff (foo)
       class(foo_t), intent(in) :: foo
    end subroutine do_stuff
  end interface

end module m

The compilation fails with this error message:

NVFORTRAN-F-0155-No default initialization in structure constructor- member do_stuff$tbp$1 (constructor.f90: 12)

I’m not entirely sure if the code is correct as it is, since there is no implementation of do_stuff. However, gfortran compiles fine.

Hi Christian,

We think the code is correct so I’ve added a problem report, TPR#36816.

As a work around, it looks like you can add a 0 in the type bound procedure spot. Though gfortran will give an error.

module m

  implicit none
  private

  type :: foo_t
     integer :: x = 0
  contains
    procedure :: do_stuff
  end type foo_t

  type(foo_t), parameter :: this_foo = foo_t(0,0)

  interface
    module subroutine do_stuff (foo)
       class(foo_t), intent(in) :: foo
    end subroutine do_stuff
  end interface

end module m
1 Like