diff --git a/flang/lib/parser/characters.cc b/flang/lib/parser/characters.cc index f156a8215f4f..8ead0b7955a3 100644 --- a/flang/lib/parser/characters.cc +++ b/flang/lib/parser/characters.cc @@ -58,11 +58,11 @@ std::optional CountCharacters( const char *limit{p + bytes}; while (p < limit) { ++chars; - if (std::optional cb{cbf(p)}) { - p += *cb; - } else { + std::optional cb{cbf(p)}; + if (!cb.has_value()) { return {}; } + p += *cb; } return {chars}; } diff --git a/flang/lib/parser/unparse.cc b/flang/lib/parser/unparse.cc index 31a9f7e9b064..03688c5c2742 100644 --- a/flang/lib/parser/unparse.cc +++ b/flang/lib/parser/unparse.cc @@ -435,6 +435,18 @@ public: Put(' '), Walk(std::get>(x.t), ", "); return false; } + bool Pre(const AttrSpec &x) { // R802 + std::visit(visitors{[&](const CoarraySpec &y) { Put("CODIMENSION["); }, + [&](const ArraySpec &y) { Put("DIMENSION("); }, + [&](const auto &) {}}, + x.u); + return true; + } + void Post(const AttrSpec &x) { + std::visit(visitors{[&](const CoarraySpec &y) { Put(']'); }, + [&](const ArraySpec &y) { Put(')'); }, [&](const auto &) {}}, + x.u); + } bool Pre(const EntityDecl &x) { // R803 Walk(std::get(x.t)); Walk("(", std::get>(x.t), ")");