diff --git a/flang/lib/Semantics/check-deallocate.cpp b/flang/lib/Semantics/check-deallocate.cpp index 7cac1c413b643..3bcd4d87b0906 100644 --- a/flang/lib/Semantics/check-deallocate.cpp +++ b/flang/lib/Semantics/check-deallocate.cpp @@ -89,6 +89,9 @@ void DeallocateChecker::Leave(const parser::DeallocateStmt &deallocateStmt) { "Object in DEALLOCATE statement is not deallocatable"_err_en_US) .Attach(std::move( whyNot->set_severity(parser::Severity::Because))); + } else if (evaluate::ExtractCoarrayRef(*expr)) { // F'2023 C955 + context_.Say(source, + "Component in DEALLOCATE statement may not be coindexed"_err_en_US); } } }, diff --git a/flang/test/Semantics/deallocate05.f90 b/flang/test/Semantics/deallocate05.f90 index bdc6998094064..382957f1005cc 100644 --- a/flang/test/Semantics/deallocate05.f90 +++ b/flang/test/Semantics/deallocate05.f90 @@ -27,6 +27,11 @@ Program deallocatetest Character(256) :: ee Procedure(Real) :: prp +type at + real, allocatable :: a +end type +type(at) :: c[*] + Allocate(rp) Deallocate(rp) @@ -67,4 +72,7 @@ Program deallocatetest !ERROR: ERRMSG may not be duplicated in a DEALLOCATE statement Deallocate(x, stat=s, errmsg=ee, errmsg=ee) +!ERROR: Component in DEALLOCATE statement may not be coindexed +deallocate(c[1]%a) + End Program deallocatetest