@@ -1106,8 +1106,9 @@ class DeclarationVisitor : public ArraySpecVisitor,
11061106 // or nullptr on error.
11071107 Symbol *DeclareStatementEntity (const parser::DoVariable &,
11081108 const std::optional<parser::IntegerTypeSpec> &);
1109- Symbol &MakeCommonBlockSymbol (const parser::Name &);
1110- Symbol &MakeCommonBlockSymbol (const std::optional<parser::Name> &);
1109+ Symbol &MakeCommonBlockSymbol (const parser::Name &, SourceName);
1110+ Symbol &MakeCommonBlockSymbol (
1111+ const std::optional<parser::Name> &, SourceName);
11111112 bool CheckUseError (const parser::Name &);
11121113 void CheckAccessibility (const SourceName &, bool , Symbol &);
11131114 void CheckCommonBlocks ();
@@ -1244,8 +1245,6 @@ class DeclarationVisitor : public ArraySpecVisitor,
12441245 bool OkToAddComponent (const parser::Name &, const Symbol *extends = nullptr );
12451246 ParamValue GetParamValue (
12461247 const parser::TypeParamValue &, common::TypeParamAttr attr);
1247- void CheckCommonBlockDerivedType (
1248- const SourceName &, const Symbol &, UnorderedSymbolSet &);
12491248 Attrs HandleSaveName (const SourceName &, Attrs);
12501249 void AddSaveName (std::set<SourceName> &, const SourceName &);
12511250 bool HandleUnrestrictedSpecificIntrinsicFunction (const parser::Name &);
@@ -5564,7 +5563,7 @@ bool DeclarationVisitor::Pre(const parser::BindEntity &x) {
55645563 if (kind == parser::BindEntity::Kind::Object) {
55655564 symbol = &HandleAttributeStmt (Attr::BIND_C, name);
55665565 } else {
5567- symbol = &MakeCommonBlockSymbol (name);
5566+ symbol = &MakeCommonBlockSymbol (name, name. source );
55685567 SetExplicitAttr (*symbol, Attr::BIND_C);
55695568 }
55705569 // 8.6.4(1)
@@ -7147,7 +7146,7 @@ bool DeclarationVisitor::Pre(const parser::SaveStmt &x) {
71477146 auto kind{std::get<parser::SavedEntity::Kind>(y.t )};
71487147 const auto &name{std::get<parser::Name>(y.t )};
71497148 if (kind == parser::SavedEntity::Kind::Common) {
7150- MakeCommonBlockSymbol (name);
7149+ MakeCommonBlockSymbol (name, name. source );
71517150 AddSaveName (specPartState_.saveInfo .commons , name.source );
71527151 } else {
71537152 HandleAttributeStmt (Attr::SAVE, name);
@@ -7227,103 +7226,29 @@ void DeclarationVisitor::CheckCommonBlocks() {
72277226 if (symbol.get <CommonBlockDetails>().objects ().empty () &&
72287227 symbol.attrs ().test (Attr::BIND_C)) {
72297228 Say (symbol.name (),
7230- " '%s' appears as a COMMON block in a BIND statement but not in"
7231- " a COMMON statement" _err_en_US);
7232- }
7233- }
7234- // check objects in common blocks
7235- for (const auto &name : specPartState_.commonBlockObjects ) {
7236- const auto *symbol{currScope ().FindSymbol (name)};
7237- if (!symbol) {
7238- continue ;
7239- }
7240- const auto &attrs{symbol->attrs ()};
7241- if (attrs.test (Attr::ALLOCATABLE)) {
7242- Say (name,
7243- " ALLOCATABLE object '%s' may not appear in a COMMON block" _err_en_US);
7244- } else if (attrs.test (Attr::BIND_C)) {
7245- Say (name,
7246- " Variable '%s' with BIND attribute may not appear in a COMMON block" _err_en_US);
7247- } else if (IsNamedConstant (*symbol)) {
7248- Say (name,
7249- " A named constant '%s' may not appear in a COMMON block" _err_en_US);
7250- } else if (IsDummy (*symbol)) {
7251- Say (name,
7252- " Dummy argument '%s' may not appear in a COMMON block" _err_en_US);
7253- } else if (symbol->IsFuncResult ()) {
7254- Say (name,
7255- " Function result '%s' may not appear in a COMMON block" _err_en_US);
7256- } else if (const DeclTypeSpec * type{symbol->GetType ()}) {
7257- if (type->category () == DeclTypeSpec::ClassStar) {
7258- Say (name,
7259- " Unlimited polymorphic pointer '%s' may not appear in a COMMON block" _err_en_US);
7260- } else if (const auto *derived{type->AsDerived ()}) {
7261- if (!IsSequenceOrBindCType (derived)) {
7262- Say (name,
7263- " Derived type '%s' in COMMON block must have the BIND or"
7264- " SEQUENCE attribute" _err_en_US);
7265- }
7266- UnorderedSymbolSet typeSet;
7267- CheckCommonBlockDerivedType (name, derived->typeSymbol (), typeSet);
7268- }
7229+ " '%s' appears as a COMMON block in a BIND statement but not in a COMMON statement" _err_en_US);
72697230 }
72707231 }
72717232 specPartState_.commonBlockObjects = {};
72727233}
72737234
7274- Symbol &DeclarationVisitor::MakeCommonBlockSymbol (const parser::Name &name) {
7275- return Resolve (name, currScope ().MakeCommonBlock (name.source ));
7235+ Symbol &DeclarationVisitor::MakeCommonBlockSymbol (
7236+ const parser::Name &name, SourceName location) {
7237+ return Resolve (name, currScope ().MakeCommonBlock (name.source , location));
72767238}
72777239Symbol &DeclarationVisitor::MakeCommonBlockSymbol (
7278- const std::optional<parser::Name> &name) {
7240+ const std::optional<parser::Name> &name, SourceName location ) {
72797241 if (name) {
7280- return MakeCommonBlockSymbol (*name);
7242+ return MakeCommonBlockSymbol (*name, location );
72817243 } else {
7282- return MakeCommonBlockSymbol (parser::Name{});
7244+ return MakeCommonBlockSymbol (parser::Name{}, location );
72837245 }
72847246}
72857247
72867248bool DeclarationVisitor::NameIsKnownOrIntrinsic (const parser::Name &name) {
72877249 return FindSymbol (name) || HandleUnrestrictedSpecificIntrinsicFunction (name);
72887250}
72897251
7290- // Check if this derived type can be in a COMMON block.
7291- void DeclarationVisitor::CheckCommonBlockDerivedType (const SourceName &name,
7292- const Symbol &typeSymbol, UnorderedSymbolSet &typeSet) {
7293- if (auto iter{typeSet.find (SymbolRef{typeSymbol})}; iter != typeSet.end ()) {
7294- return ;
7295- }
7296- typeSet.emplace (typeSymbol);
7297- if (const auto *scope{typeSymbol.scope ()}) {
7298- for (const auto &pair : *scope) {
7299- const Symbol &component{*pair.second };
7300- if (component.attrs ().test (Attr::ALLOCATABLE)) {
7301- Say2 (name,
7302- " Derived type variable '%s' may not appear in a COMMON block"
7303- " due to ALLOCATABLE component" _err_en_US,
7304- component.name (), " Component with ALLOCATABLE attribute" _en_US);
7305- return ;
7306- }
7307- const auto *details{component.detailsIf <ObjectEntityDetails>()};
7308- if (component.test (Symbol::Flag::InDataStmt) ||
7309- (details && details->init ())) {
7310- Say2 (name,
7311- " Derived type variable '%s' may not appear in a COMMON block due to component with default initialization" _err_en_US,
7312- component.name (), " Component with default initialization" _en_US);
7313- return ;
7314- }
7315- if (details) {
7316- if (const auto *type{details->type ()}) {
7317- if (const auto *derived{type->AsDerived ()}) {
7318- const Symbol &derivedTypeSymbol{derived->typeSymbol ()};
7319- CheckCommonBlockDerivedType (name, derivedTypeSymbol, typeSet);
7320- }
7321- }
7322- }
7323- }
7324- }
7325- }
7326-
73277252bool DeclarationVisitor::HandleUnrestrictedSpecificIntrinsicFunction (
73287253 const parser::Name &name) {
73297254 if (auto interface{context ().intrinsics ().IsSpecificIntrinsicFunction (
@@ -9655,7 +9580,7 @@ void ResolveNamesVisitor::CreateCommonBlockSymbols(
96559580 const parser::CommonStmt &commonStmt) {
96569581 for (const parser::CommonStmt::Block &block : commonStmt.blocks ) {
96579582 const auto &[name, objects] = block.t ;
9658- Symbol &commonBlock{MakeCommonBlockSymbol (name)};
9583+ Symbol &commonBlock{MakeCommonBlockSymbol (name, commonStmt. source )};
96599584 for (const auto &object : objects) {
96609585 Symbol &obj{DeclareObjectEntity (std::get<parser::Name>(object.t ))};
96619586 if (auto *details{obj.detailsIf <ObjectEntityDetails>()}) {
0 commit comments