Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29106 Discussions

No error reported for using null() in a constructor to fill a non-allocatable/non-pointer component

Arjen_Markus
Honored Contributor II
615 Views

In a post on Fortran discourse (https://fortran-lang.discourse.group/t/example-from-reinhold-baders-tutorial-curious-result/9298/9)  I present a program that is accepted by ifx but not by gfortran. It seems that the ifx compiler (at least the version I used) is ignoring the error in it.

Here is the program:

! fillnull.f90 --
!     Use a constructor with null() to see what happens to ordinary scalars
!
!     This is not accepted by gfortran, but it is by ifx 2025.0.0
!
program fillnull
    implicit none

    type :: simple
        integer :: value(1) = [10]
    end type simple

    type(simple) :: a

    write(*,*) 'Default: ', a

    a = simple(null())

    write(*,*) 'After null(): ', a

end program fillnull

If you change the value component to a scalar, it is also accepted without a warning.

0 Kudos
1 Solution
Igor_V_Intel
Employee
481 Views

Thank you for reporting it to us. I have escalated it to the development team and the fix will come with upcoming compiler updates.


View solution in original post

4 Replies
Steve_Lionel
Honored Contributor III
520 Views

Here's what NAG Fortran says:

NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7222
Error: t.f90, line 12: In constructor for type SIMPLE, value for non-allocatable non-pointer component VALUE is intrinsic function NULL reference

0 Kudos
Igor_V_Intel
Employee
482 Views

Thank you for reporting it to us. I have escalated it to the development team and the fix will come with upcoming compiler updates.


Arjen_Markus
Honored Contributor II
416 Views

Thanks for picking this up. I have no idea how common this feature is used, but getting a proper warning/error message is important enough, perhaps especially for rarely used features.

0 Kudos
Igor_V_Intel
Employee
172 Views

The ifx compiler version 2025.1 emits an error  #9211 for this code:

$ ifx test.f90

test.f90(12): error #9211: In a structure constructor, the intrinsic function NULL must only be used for a POINTER or ALLOCATABLE component.  [VALUE]

  a = simple(null())

---------------^

compilation aborted for test.f90 (code 1)

So, the problem is corrected in the latest compiler release.


0 Kudos
Reply