Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions flang/lib/Parser/Fortran-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,10 +1304,16 @@ TYPE_PARSER(extension<LanguageFeature::CUDA>(construct<CUDAAttributesStmt>(
defaulted(
maybe("::"_tok) >> nonemptyList("expected names"_err_en_US, name)))))

// Subtle: the name includes the surrounding slashes, which avoids
// Subtle: A structure's name includes the surrounding slashes, which avoids
// clashes with other uses of the name in the same scope.
TYPE_PARSER(construct<StructureStmt>(
"STRUCTURE" >> maybe(sourced("/" >> name / "/")), optionalList(entityDecl)))
constexpr auto structureName{maybe(sourced("/" >> name / "/"))};

// Note that Parser<StructureStmt>{} has a mandatory list of entity-decls
// and is used only by NestedStructureStmt{}.Parse() in user-state.cpp.
TYPE_PARSER(construct<StructureStmt>("STRUCTURE" >> structureName,
localRecovery(
"entity declarations are required on a nested structure"_err_en_US,
nonemptyList(entityDecl), ok)))

constexpr auto nestedStructureDef{
CONTEXT_PARSER("nested STRUCTURE definition"_en_US,
Expand All @@ -1323,7 +1329,9 @@ TYPE_PARSER(construct<StructureField>(statement(StructureComponents{})) ||
TYPE_CONTEXT_PARSER("STRUCTURE definition"_en_US,
extension<LanguageFeature::DECStructures>(
"nonstandard usage: STRUCTURE"_port_en_US,
construct<StructureDef>(statement(Parser<StructureStmt>{}),
construct<StructureDef>(
statement(construct<StructureStmt>(
"STRUCTURE" >> structureName, optionalList(entityDecl))),
many(Parser<StructureField>{}),
statement(construct<StructureDef::EndStructureStmt>(
"END STRUCTURE"_tok)))))
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/struct03.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
structure /s/
!ERROR: entity declarations are required on a nested structure
structure /nested/
end structure
end structure
end