@@ -60,7 +60,7 @@ constexpr Legality IsLegalDoTerm(const parser::Statement<A> &) {
60
60
std::is_same_v<A, parser::EndWhereStmt>) {
61
61
// Executable construct end statements are also supported as
62
62
// an extension but they need special care because the associated
63
- // construct create there own scope.
63
+ // construct create their own scope.
64
64
return Legality::formerly;
65
65
} else {
66
66
return Legality::never;
@@ -224,10 +224,10 @@ class ParseTreeAnalyzer {
224
224
parser::BlockStmt, parser::ChangeTeamStmt, parser::CriticalStmt,
225
225
parser::IfThenStmt, parser::NonLabelDoStmt, parser::SelectCaseStmt,
226
226
parser::SelectRankStmt, parser::SelectTypeStmt>;
227
- using LabeledConstructEndStmts =
228
- std::tuple< parser::EndAssociateStmt , parser::EndBlockStmt ,
229
- parser::EndChangeTeamStmt , parser::EndCriticalStmt ,
230
- parser::EndDoStmt , parser::EndIfStmt , parser::EndSelectStmt >;
227
+ using LabeledConstructEndStmts = std::tuple<parser::EndAssociateStmt,
228
+ parser::EndBlockStmt , parser::EndChangeTeamStmt ,
229
+ parser::EndCriticalStmt, parser::EndDoStmt , parser::EndForallStmt ,
230
+ parser::EndIfStmt , parser::EndSelectStmt , parser::EndWhereStmt >;
231
231
using LabeledProgramUnitEndStmts =
232
232
std::tuple<parser::EndFunctionStmt, parser::EndMpSubprogramStmt,
233
233
parser::EndProgramStmt, parser::EndSubroutineStmt>;
@@ -294,10 +294,10 @@ class ParseTreeAnalyzer {
294
294
return SwitchToNewScope ();
295
295
}
296
296
bool Pre (const parser::WhereConstruct &whereConstruct) {
297
- return PushConstructNameWithoutBlock (whereConstruct);
297
+ return PushConstructName (whereConstruct);
298
298
}
299
299
bool Pre (const parser::ForallConstruct &forallConstruct) {
300
- return PushConstructNameWithoutBlock (forallConstruct);
300
+ return PushConstructName (forallConstruct);
301
301
}
302
302
303
303
void Post (const parser::AssociateConstruct &associateConstruct) {
@@ -327,12 +327,11 @@ class ParseTreeAnalyzer {
327
327
void Post (const parser::SelectTypeConstruct &selectTypeConstruct) {
328
328
PopConstructName (selectTypeConstruct);
329
329
}
330
-
331
330
void Post (const parser::WhereConstruct &whereConstruct) {
332
- PopConstructNameWithoutBlock (whereConstruct);
331
+ PopConstructName (whereConstruct);
333
332
}
334
333
void Post (const parser::ForallConstruct &forallConstruct) {
335
- PopConstructNameWithoutBlock (forallConstruct);
334
+ PopConstructName (forallConstruct);
336
335
}
337
336
338
337
// Checks for missing or mismatching names on various constructs (e.g., IF)
@@ -570,18 +569,6 @@ class ParseTreeAnalyzer {
570
569
}
571
570
return PushSubscope ();
572
571
}
573
- template <typename A> bool PushConstructNameWithoutBlock (const A &a) {
574
- const auto &optionalName{std::get<0 >(std::get<0 >(a.t ).statement .t )};
575
- if (optionalName) {
576
- constructNames_.emplace_back (optionalName->ToString ());
577
- }
578
- return true ;
579
- }
580
-
581
- template <typename A> void PopConstructNameWithoutBlock (const A &a) {
582
- CheckName (a);
583
- PopConstructNameIfPresent (a);
584
- }
585
572
template <typename A> void PopConstructNameIfPresent (const A &a) {
586
573
const auto &optionalName{std::get<0 >(std::get<0 >(a.t ).statement .t )};
587
574
if (optionalName) {
@@ -962,12 +949,15 @@ void CheckScopeConstraints(const SourceStmtList &stmts,
962
949
} else if (!InInclusiveScope (scopes, scope, target.proxyForScope )) {
963
950
// Clause 11.1.2.1 prohibits transfer of control to the interior of a
964
951
// block from outside the block, but this does not apply to formats.
952
+ // C1038 and C1034 forbid statements in FORALL and WHERE constructs
953
+ // (resp.) from being branch targets.
965
954
if (target.labeledStmtClassificationSet .test (
966
955
TargetStatementEnum::Format)) {
967
956
continue ;
968
957
}
969
- context.Say (
970
- position, " Label '%u' is not in scope" _en_US, SayLabel (label));
958
+ context.Say (position,
959
+ " Label '%u' is in a construct that prevents its use as a branch target here" _en_US,
960
+ SayLabel (label));
971
961
}
972
962
}
973
963
}
0 commit comments