[flang] Catch error: base of DATA statement object can't be a pointer

A pointer with subscripts, substring indices, or components cannot
be initialized by a DATA statement (although of course a whole pointer
can be so).  Catch the missing cases.

Differential Revision: https://reviews.llvm.org/D109931
This commit is contained in:
peter klausler 2021-09-14 13:37:11 -07:00
parent cbbf2e8c8a
commit 57705df2de
2 changed files with 9 additions and 1 deletions

View File

@ -70,6 +70,8 @@ public:
: IsHostAssociated(symbol, scope) ? "Host-associated object"
: IsUseAssociated(symbol, scope) ? "USE-associated object"
: symbol.has<AssocEntityDetails>() ? "Construct association"
: IsPointer(symbol) && (hasComponent_ || hasSubscript_)
? "Target of pointer"
: nullptr}) {
context_.Say(source_,
"%s '%s' must not be initialized in a DATA statement"_err_en_US,

View File

@ -65,6 +65,10 @@ module m
type(large) :: largeNumberArray(i)
type(large) :: largeArray(5)
character :: name(i)
type small
real :: x
end type
type(small), pointer :: sp
!C877
!ERROR: Default-initialized 'largenumber' must not be initialized in a DATA statement
DATA(largeNumber % numsArray(j) % headOfTheList, j = 1, 10) / 10 * NULL() /
@ -92,6 +96,8 @@ module m
!C876
!ERROR: Automatic variable 'name' must not be initialized in a DATA statement
DATA name( : 2) / 'Ancd' /
!ERROR: Target of pointer 'sp' must not be initialized in a DATA statement
DATA sp%x / 1.0 /
end
end