Nvfortran: Possible bug in derived data type initialization

Hello,
I think I may have found a bug in nvfortran 24.7-0 for the initialization of derived data types including pointers.

type :: FooType
    real                       :: rbar = -999.
    character(len=10), pointer :: pbar => NULL()
    integer, dimension(17)      :: ibar = -999
end type FooType

type(FooType), target :: foo = &
    FooType(                   &
!            pbar     = NULL(),     &
        ibar       = 0,        &
        rbar       = 1         &
    )

END

gives me two errors:

NVFORTRAN-S-0067-Too many data constants in initialization statement (t.f90: 7)
NVFORTRAN-S-0066-Too few data constants in initialization statement (t.f90: 7)

which is kind of contradictory :-)

I can get rid of the “Too many” by reducing the dimension of ibar to 16, for example, which is odd, but this seems to be only a cascade effect. The general problem instead appears to be the default value for the pointer pbar. If activating the pbar = NULL() in the constructor initialization, everything is well, or if the default value for pbar is omitted, also no error is produced. You can play around with the code a little bit, to trigger the error(s) or not by small changes, but I think even a pointer should be initializable to a default, and overridden in the constructor only if needed.

Please bear some patience with me in case I misinterprete the FORTRAN standard in this regard.

Thanks for your support.

Regards,
Manuel

Thanks for the report Manuel. I’ve filed a problem report, TPR #36498, and sent it to engineering for review. It looks similar to another issue we fixed back in 24.1 where allocatable components in a structure constructor were giving the same error. Might be the same issue, but just with pointers.

Note that if it is related and easy, engineering will likely get a fix in. However they have been deferring fixing issues with new language features (this is a F2008 feature) since we’re working with the LLVM community on a new “f18” flang compiler to support more modern Fortran, and your code compiles correctly with this new compiler.

-Mat

Good to hear. Do you dare to guesstimate when f18 may find its way into NVHPC?
Thank you very much!

Regars,
Manuel

Wish I could. Engineering is hard at work getting it in shape but we’re not ready to announce a release date.

Of course, you can always grab the latest community version from the above link.