Index: flang/lib/Semantics/check-declarations.cpp =================================================================== --- flang/lib/Semantics/check-declarations.cpp +++ flang/lib/Semantics/check-declarations.cpp @@ -1045,6 +1045,11 @@ symbol, *stmtFunction, context_.foldingContext())}) { SayWithDeclaration(symbol, std::move(*msg)); } + if (GetProgramUnitOrBlockConstructContaining(symbol).kind() == + Scope::Kind::BlockConstruct) { // C1107 + messages_.Say(symbol.name(), + "A statement function definition may not appear in a BLOCK construct"_err_en_US); + } } if (IsElementalProcedure(symbol)) { // See comment on the similar check in CheckProcEntity() Index: flang/lib/Semantics/resolve-names.cpp =================================================================== --- flang/lib/Semantics/resolve-names.cpp +++ flang/lib/Semantics/resolve-names.cpp @@ -7700,7 +7700,6 @@ ConstructVisitor::Post(x); } bool ResolveNamesVisitor::Pre(const parser::StmtFunctionStmt &x) { - CheckNotInBlock("STATEMENT FUNCTION"); // C1107 if (HandleStmtFunction(x)) { return false; } else { Index: flang/test/Semantics/blockconstruct01.f90 =================================================================== --- flang/test/Semantics/blockconstruct01.f90 +++ flang/test/Semantics/blockconstruct01.f90 @@ -56,11 +56,11 @@ end subroutine s7_c1107 - integer x + integer x, arr(1) inc(x) = x + 1 block - !ERROR: STATEMENT FUNCTION statement is not allowed in a BLOCK construct + !ERROR: A statement function definition may not appear in a BLOCK construct dec(x) = x - 1 + arr(x) = x - 1 ! ok end block end -