1 //===-- lib/Semantics/check-namelist.cpp ----------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "check-namelist.h" 10 11 namespace Fortran::semantics { 12 13 void NamelistChecker::Leave(const parser::NamelistStmt &nmlStmt) { 14 for (const auto &x : nmlStmt.v) { 15 if (const auto *nml{std::get<parser::Name>(x.t).symbol}) { 16 for (const auto &nmlObjName : std::get<std::list<parser::Name>>(x.t)) { 17 const auto *nmlObjSymbol{nmlObjName.symbol}; 18 if (nmlObjSymbol) { 19 if (IsAssumedSizeArray(*nmlObjSymbol)) { // C8104 20 context_.Say(nmlObjName.source, 21 "A namelist group object '%s' must not be assumed-size"_err_en_US, 22 nmlObjSymbol->name()); 23 } 24 if (nml->attrs().test(Attr::PUBLIC) && 25 nmlObjSymbol->attrs().test(Attr::PRIVATE)) { // C8105 26 context_.Say(nmlObjName.source, 27 "A PRIVATE namelist group object '%s' must not be in a " 28 "PUBLIC namelist"_err_en_US, 29 nmlObjSymbol->name()); 30 } 31 } 32 } 33 } 34 } 35 } 36 37 void NamelistChecker::Leave(const parser::LocalitySpec::Reduce &x) { 38 for (const parser::Name &name : std::get<std::list<parser::Name>>(x.t)) { 39 Symbol *sym{name.symbol}; 40 // This is not disallowed by the standard, but would be difficult to 41 // support. This has to go here not with the other checks for locality specs 42 // in resolve-names.cpp so that it is done after the InNamelist flag is 43 // applied. 44 if (sym && sym->GetUltimate().test(Symbol::Flag::InNamelist)) { 45 context_.Say(name.source, 46 "NAMELIST variable '%s' not allowed in a REDUCE locality-spec"_err_en_US, 47 name.ToString()); 48 } 49 } 50 } 51 52 } // namespace Fortran::semantics 53