@@ -1106,8 +1106,9 @@ class DeclarationVisitor : public ArraySpecVisitor,
1106
1106
// or nullptr on error.
1107
1107
Symbol *DeclareStatementEntity (const parser::DoVariable &,
1108
1108
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);
1111
1112
bool CheckUseError (const parser::Name &);
1112
1113
void CheckAccessibility (const SourceName &, bool , Symbol &);
1113
1114
void CheckCommonBlocks ();
@@ -1244,8 +1245,6 @@ class DeclarationVisitor : public ArraySpecVisitor,
1244
1245
bool OkToAddComponent (const parser::Name &, const Symbol *extends = nullptr );
1245
1246
ParamValue GetParamValue (
1246
1247
const parser::TypeParamValue &, common::TypeParamAttr attr);
1247
- void CheckCommonBlockDerivedType (
1248
- const SourceName &, const Symbol &, UnorderedSymbolSet &);
1249
1248
Attrs HandleSaveName (const SourceName &, Attrs);
1250
1249
void AddSaveName (std::set<SourceName> &, const SourceName &);
1251
1250
bool HandleUnrestrictedSpecificIntrinsicFunction (const parser::Name &);
@@ -5564,7 +5563,7 @@ bool DeclarationVisitor::Pre(const parser::BindEntity &x) {
5564
5563
if (kind == parser::BindEntity::Kind::Object) {
5565
5564
symbol = &HandleAttributeStmt (Attr::BIND_C, name);
5566
5565
} else {
5567
- symbol = &MakeCommonBlockSymbol (name);
5566
+ symbol = &MakeCommonBlockSymbol (name, name. source );
5568
5567
SetExplicitAttr (*symbol, Attr::BIND_C);
5569
5568
}
5570
5569
// 8.6.4(1)
@@ -7147,7 +7146,7 @@ bool DeclarationVisitor::Pre(const parser::SaveStmt &x) {
7147
7146
auto kind{std::get<parser::SavedEntity::Kind>(y.t )};
7148
7147
const auto &name{std::get<parser::Name>(y.t )};
7149
7148
if (kind == parser::SavedEntity::Kind::Common) {
7150
- MakeCommonBlockSymbol (name);
7149
+ MakeCommonBlockSymbol (name, name. source );
7151
7150
AddSaveName (specPartState_.saveInfo .commons , name.source );
7152
7151
} else {
7153
7152
HandleAttributeStmt (Attr::SAVE, name);
@@ -7227,103 +7226,29 @@ void DeclarationVisitor::CheckCommonBlocks() {
7227
7226
if (symbol.get <CommonBlockDetails>().objects ().empty () &&
7228
7227
symbol.attrs ().test (Attr::BIND_C)) {
7229
7228
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);
7269
7230
}
7270
7231
}
7271
7232
specPartState_.commonBlockObjects = {};
7272
7233
}
7273
7234
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));
7276
7238
}
7277
7239
Symbol &DeclarationVisitor::MakeCommonBlockSymbol (
7278
- const std::optional<parser::Name> &name) {
7240
+ const std::optional<parser::Name> &name, SourceName location ) {
7279
7241
if (name) {
7280
- return MakeCommonBlockSymbol (*name);
7242
+ return MakeCommonBlockSymbol (*name, location );
7281
7243
} else {
7282
- return MakeCommonBlockSymbol (parser::Name{});
7244
+ return MakeCommonBlockSymbol (parser::Name{}, location );
7283
7245
}
7284
7246
}
7285
7247
7286
7248
bool DeclarationVisitor::NameIsKnownOrIntrinsic (const parser::Name &name) {
7287
7249
return FindSymbol (name) || HandleUnrestrictedSpecificIntrinsicFunction (name);
7288
7250
}
7289
7251
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
-
7327
7252
bool DeclarationVisitor::HandleUnrestrictedSpecificIntrinsicFunction (
7328
7253
const parser::Name &name) {
7329
7254
if (auto interface{context ().intrinsics ().IsSpecificIntrinsicFunction (
@@ -9655,7 +9580,7 @@ void ResolveNamesVisitor::CreateCommonBlockSymbols(
9655
9580
const parser::CommonStmt &commonStmt) {
9656
9581
for (const parser::CommonStmt::Block &block : commonStmt.blocks ) {
9657
9582
const auto &[name, objects] = block.t ;
9658
- Symbol &commonBlock{MakeCommonBlockSymbol (name)};
9583
+ Symbol &commonBlock{MakeCommonBlockSymbol (name, commonStmt. source )};
9659
9584
for (const auto &object : objects) {
9660
9585
Symbol &obj{DeclareObjectEntity (std::get<parser::Name>(object.t ))};
9661
9586
if (auto *details{obj.detailsIf <ObjectEntityDetails>()}) {
0 commit comments