diff --git a/flang/lib/Semantics/resolve-labels.cpp b/flang/lib/Semantics/resolve-labels.cpp --- a/flang/lib/Semantics/resolve-labels.cpp +++ b/flang/lib/Semantics/resolve-labels.cpp @@ -935,6 +935,12 @@ parser::MessageFormattedText{ "Label '%u' was not found"_err_en_US, SayLabel(label)}); } else if (!InInclusiveScope(scopes, scope, target.proxyForScope)) { + // Clause 11.1.2.1 prohibits transfer of control to the interior of a + // block from outside the block, but this does not apply to formats. + if (target.labeledStmtClassificationSet.test( + TargetStatementEnum::Format)) { + continue; + } context.Say(position, parser::MessageFormattedText{ "Label '%u' is not in scope"_en_US, SayLabel(label)}); diff --git a/flang/test/Semantics/io07.f90 b/flang/test/Semantics/io07.f90 --- a/flang/test/Semantics/io07.f90 +++ b/flang/test/Semantics/io07.f90 @@ -17,6 +17,11 @@ 2011 format(:2L2) 2012 format(2L2 : 2L2) + write(*,2013) 'Hello' + if (2+2.eq.4) then +2013 format(A10) ! ok to reference outside the if block + endif + ! C1302 warnings; no errors 2051 format(1X3/) 2052 format(1X003/)