Skip to content

Commit

Permalink
[flang] Enforce F'2023 C7125
Browse files Browse the repository at this point in the history
An item whose declared type is ABSTRACT may not appear in an
array constructor.

Differential Revision: https://reviews.llvm.org/D155969
  • Loading branch information
klausler committed Jul 21, 2023
1 parent c381a94 commit e7cb677
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,14 @@ void ArrayConstructorContext::Push(MaybeExpr &&x) {
messageDisplayedSet_ |= 8;
}
return;
} else if (dyType->category() == TypeCategory::Derived &&
dyType->GetDerivedTypeSpec().typeSymbol().attrs().test(
semantics::Attr::ABSTRACT)) { // F'2023 C7125
if (!(messageDisplayedSet_ & 0x200)) {
exprAnalyzer_.Say(
"An item whose declared type is ABSTRACT may not appear in an array constructor"_err_en_US);
messageDisplayedSet_ |= 0x200;
}
}
DynamicTypeWithLength xType{dyType.value()};
if (Expr<SomeCharacter> * charExpr{UnwrapExpr<Expr<SomeCharacter>>(*x)}) {
Expand Down
3 changes: 2 additions & 1 deletion flang/test/Semantics/array-constr-values.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ subroutine arrayconstructorvalues()
!ERROR: Cannot have an unlimited polymorphic value in an array constructor
intarray = (/ unlim_polymorphic, 2, 3, 4, 5/)

! C7114
! C7114, F'2023 C7125
!ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types INTEGER(4) and TYPE(base_type)
!ERROR: ABSTRACT derived type 'base_type' may not be used in a structure constructor
!ERROR: An item whose declared type is ABSTRACT may not appear in an array constructor
!ERROR: Values in array constructor must have the same declared type when no explicit type appears
intarray = (/ base_type(10), 2, 3, 4, 5 /)

Expand Down

0 comments on commit e7cb677

Please sign in to comment.