peter klausler a94b721d26 [flang] Improve error message for misuse of NULL(mold) as data statement constant
While "null()" is accepted as a data statement constant when it
corresponds to a pointer object, "null(mold=p)" and "null(p)"
are not allowed.  The current error messages simply complain
that null is not an array.  This patch adds a context-sensitive
message to the effect that a data statement constant followed
by non-empty parentheses must be an array or structure constructor.

(Note that f18 can't simply special-case the name "null" when parsing
data statement constants, since programs are free to repurpose that
name as an array or derived type.)

Differential Revision: https://reviews.llvm.org/D112740
2021-10-28 15:20:41 -07:00

98 lines
2.1 KiB
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1
! Tests valid and invalid NULL initializers
module m1
implicit none
!ERROR: No explicit type declared for 'null'
private :: null
end module
module m2
implicit none
private :: null
integer, pointer :: p => null()
end module
module m3
private :: null
integer, pointer :: p => null()
end module
module m4
intrinsic :: null
integer, pointer :: p => null()
end module
module m5
external :: null
!ERROR: Pointer initializer must be intrinsic NULL()
integer, pointer :: p => null()
end module
module m6
!ERROR: Symbol 'null' cannot have both INTRINSIC and EXTERNAL attributes
integer, pointer :: p => null()
external :: null
end module
module m7
interface
function null() result(p)
integer, pointer :: p
end function
end interface
!ERROR: Pointer initializer must be intrinsic NULL()
integer, pointer :: p => null()
end module
module m8
integer, pointer :: p => null()
interface
!ERROR: 'null' is already declared in this scoping unit
function null() result(p)
integer, pointer :: p
end function
end interface
end module
module m9a
intrinsic :: null
contains
function foo()
integer, pointer :: foo
foo => null()
end function
end module
module m9b
use m9a, renamed => null, null => foo
integer, pointer :: p => renamed()
!ERROR: Pointer initializer must be intrinsic NULL()
integer, pointer :: q => null()
integer, pointer :: d1, d2
data d1/renamed()/
!ERROR: An initial data target must be a designator with constant subscripts
data d2/null()/
end module
subroutine m10
real, pointer :: x, y
!ERROR: 'null' must be an array or structure constructor if used with non-empty parentheses as a DATA statement constant
data x/null(y)/
end
subroutine m11
type :: null
integer :: mold
end type
type(null) :: obj(2)
integer, parameter :: j = 0
data obj/null(mold=j), null(j)/ ! both fine
end subroutine
subroutine m12
integer, parameter :: j = 1
integer, target, save :: null(1)
integer, pointer :: p
data p/null(j)/ ! ok
end subroutine