@@ -1105,8 +1105,9 @@ class DeclarationVisitor : public ArraySpecVisitor,
11051105 // or nullptr on error.
11061106 Symbol *DeclareStatementEntity (const parser::DoVariable &,
11071107 const std::optional<parser::IntegerTypeSpec> &);
1108- Symbol &MakeCommonBlockSymbol (const parser::Name &);
1109- Symbol &MakeCommonBlockSymbol (const std::optional<parser::Name> &);
1108+ Symbol &MakeCommonBlockSymbol (const parser::Name &, SourceName);
1109+ Symbol &MakeCommonBlockSymbol (
1110+ const std::optional<parser::Name> &, SourceName);
11101111 bool CheckUseError (const parser::Name &);
11111112 void CheckAccessibility (const SourceName &, bool , Symbol &);
11121113 void CheckCommonBlocks ();
@@ -1243,8 +1244,6 @@ class DeclarationVisitor : public ArraySpecVisitor,
12431244 bool OkToAddComponent (const parser::Name &, const Symbol *extends = nullptr );
12441245 ParamValue GetParamValue (
12451246 const parser::TypeParamValue &, common::TypeParamAttr attr);
1246- void CheckCommonBlockDerivedType (
1247- const SourceName &, const Symbol &, UnorderedSymbolSet &);
12481247 Attrs HandleSaveName (const SourceName &, Attrs);
12491248 void AddSaveName (std::set<SourceName> &, const SourceName &);
12501249 bool HandleUnrestrictedSpecificIntrinsicFunction (const parser::Name &);
@@ -5508,7 +5507,7 @@ bool DeclarationVisitor::Pre(const parser::BindEntity &x) {
55085507 if (kind == parser::BindEntity::Kind::Object) {
55095508 symbol = &HandleAttributeStmt (Attr::BIND_C, name);
55105509 } else {
5511- symbol = &MakeCommonBlockSymbol (name);
5510+ symbol = &MakeCommonBlockSymbol (name, name. source );
55125511 SetExplicitAttr (*symbol, Attr::BIND_C);
55135512 }
55145513 // 8.6.4(1)
@@ -7090,7 +7089,7 @@ bool DeclarationVisitor::Pre(const parser::SaveStmt &x) {
70907089 auto kind{std::get<parser::SavedEntity::Kind>(y.t )};
70917090 const auto &name{std::get<parser::Name>(y.t )};
70927091 if (kind == parser::SavedEntity::Kind::Common) {
7093- MakeCommonBlockSymbol (name);
7092+ MakeCommonBlockSymbol (name, name. source );
70947093 AddSaveName (specPartState_.saveInfo .commons , name.source );
70957094 } else {
70967095 HandleAttributeStmt (Attr::SAVE, name);
@@ -7170,103 +7169,29 @@ void DeclarationVisitor::CheckCommonBlocks() {
71707169 if (symbol.get <CommonBlockDetails>().objects ().empty () &&
71717170 symbol.attrs ().test (Attr::BIND_C)) {
71727171 Say (symbol.name (),
7173- " '%s' appears as a COMMON block in a BIND statement but not in"
7174- " a COMMON statement" _err_en_US);
7175- }
7176- }
7177- // check objects in common blocks
7178- for (const auto &name : specPartState_.commonBlockObjects ) {
7179- const auto *symbol{currScope ().FindSymbol (name)};
7180- if (!symbol) {
7181- continue ;
7182- }
7183- const auto &attrs{symbol->attrs ()};
7184- if (attrs.test (Attr::ALLOCATABLE)) {
7185- Say (name,
7186- " ALLOCATABLE object '%s' may not appear in a COMMON block" _err_en_US);
7187- } else if (attrs.test (Attr::BIND_C)) {
7188- Say (name,
7189- " Variable '%s' with BIND attribute may not appear in a COMMON block" _err_en_US);
7190- } else if (IsNamedConstant (*symbol)) {
7191- Say (name,
7192- " A named constant '%s' may not appear in a COMMON block" _err_en_US);
7193- } else if (IsDummy (*symbol)) {
7194- Say (name,
7195- " Dummy argument '%s' may not appear in a COMMON block" _err_en_US);
7196- } else if (symbol->IsFuncResult ()) {
7197- Say (name,
7198- " Function result '%s' may not appear in a COMMON block" _err_en_US);
7199- } else if (const DeclTypeSpec * type{symbol->GetType ()}) {
7200- if (type->category () == DeclTypeSpec::ClassStar) {
7201- Say (name,
7202- " Unlimited polymorphic pointer '%s' may not appear in a COMMON block" _err_en_US);
7203- } else if (const auto *derived{type->AsDerived ()}) {
7204- if (!IsSequenceOrBindCType (derived)) {
7205- Say (name,
7206- " Derived type '%s' in COMMON block must have the BIND or"
7207- " SEQUENCE attribute" _err_en_US);
7208- }
7209- UnorderedSymbolSet typeSet;
7210- CheckCommonBlockDerivedType (name, derived->typeSymbol (), typeSet);
7211- }
7172+ " '%s' appears as a COMMON block in a BIND statement but not in a COMMON statement" _err_en_US);
72127173 }
72137174 }
72147175 specPartState_.commonBlockObjects = {};
72157176}
72167177
7217- Symbol &DeclarationVisitor::MakeCommonBlockSymbol (const parser::Name &name) {
7218- return Resolve (name, currScope ().MakeCommonBlock (name.source ));
7178+ Symbol &DeclarationVisitor::MakeCommonBlockSymbol (
7179+ const parser::Name &name, SourceName location) {
7180+ return Resolve (name, currScope ().MakeCommonBlock (name.source , location));
72197181}
72207182Symbol &DeclarationVisitor::MakeCommonBlockSymbol (
7221- const std::optional<parser::Name> &name) {
7183+ const std::optional<parser::Name> &name, SourceName location ) {
72227184 if (name) {
7223- return MakeCommonBlockSymbol (*name);
7185+ return MakeCommonBlockSymbol (*name, location );
72247186 } else {
7225- return MakeCommonBlockSymbol (parser::Name{});
7187+ return MakeCommonBlockSymbol (parser::Name{}, location );
72267188 }
72277189}
72287190
72297191bool DeclarationVisitor::NameIsKnownOrIntrinsic (const parser::Name &name) {
72307192 return FindSymbol (name) || HandleUnrestrictedSpecificIntrinsicFunction (name);
72317193}
72327194
7233- // Check if this derived type can be in a COMMON block.
7234- void DeclarationVisitor::CheckCommonBlockDerivedType (const SourceName &name,
7235- const Symbol &typeSymbol, UnorderedSymbolSet &typeSet) {
7236- if (auto iter{typeSet.find (SymbolRef{typeSymbol})}; iter != typeSet.end ()) {
7237- return ;
7238- }
7239- typeSet.emplace (typeSymbol);
7240- if (const auto *scope{typeSymbol.scope ()}) {
7241- for (const auto &pair : *scope) {
7242- const Symbol &component{*pair.second };
7243- if (component.attrs ().test (Attr::ALLOCATABLE)) {
7244- Say2 (name,
7245- " Derived type variable '%s' may not appear in a COMMON block"
7246- " due to ALLOCATABLE component" _err_en_US,
7247- component.name (), " Component with ALLOCATABLE attribute" _en_US);
7248- return ;
7249- }
7250- const auto *details{component.detailsIf <ObjectEntityDetails>()};
7251- if (component.test (Symbol::Flag::InDataStmt) ||
7252- (details && details->init ())) {
7253- Say2 (name,
7254- " Derived type variable '%s' may not appear in a COMMON block due to component with default initialization" _err_en_US,
7255- component.name (), " Component with default initialization" _en_US);
7256- return ;
7257- }
7258- if (details) {
7259- if (const auto *type{details->type ()}) {
7260- if (const auto *derived{type->AsDerived ()}) {
7261- const Symbol &derivedTypeSymbol{derived->typeSymbol ()};
7262- CheckCommonBlockDerivedType (name, derivedTypeSymbol, typeSet);
7263- }
7264- }
7265- }
7266- }
7267- }
7268- }
7269-
72707195bool DeclarationVisitor::HandleUnrestrictedSpecificIntrinsicFunction (
72717196 const parser::Name &name) {
72727197 if (auto interface{context ().intrinsics ().IsSpecificIntrinsicFunction (
@@ -9598,7 +9523,7 @@ void ResolveNamesVisitor::CreateCommonBlockSymbols(
95989523 const parser::CommonStmt &commonStmt) {
95999524 for (const parser::CommonStmt::Block &block : commonStmt.blocks ) {
96009525 const auto &[name, objects] = block.t ;
9601- Symbol &commonBlock{MakeCommonBlockSymbol (name)};
9526+ Symbol &commonBlock{MakeCommonBlockSymbol (name, commonStmt. source )};
96029527 for (const auto &object : objects) {
96039528 Symbol &obj{DeclareObjectEntity (std::get<parser::Name>(object.t ))};
96049529 if (auto *details{obj.detailsIf <ObjectEntityDetails>()}) {
0 commit comments