@@ -474,15 +474,15 @@ class FuncResultStack {
474
474
~FuncResultStack ();
475
475
476
476
struct FuncInfo {
477
- explicit FuncInfo (const Scope &s) : scope{s} {}
477
+ FuncInfo (const Scope &s, SourceName at ) : scope{s}, source{at } {}
478
478
const Scope &scope;
479
+ SourceName source;
479
480
// Parse tree of the type specification in the FUNCTION prefix
480
481
const parser::DeclarationTypeSpec *parsedType{nullptr };
481
482
// Name of the function RESULT in the FUNCTION suffix, if any
482
483
const parser::Name *resultName{nullptr };
483
484
// Result symbol
484
485
Symbol *resultSymbol{nullptr };
485
- std::optional<SourceName> source;
486
486
bool inFunctionStmt{false }; // true between Pre/Post of FunctionStmt
487
487
};
488
488
@@ -492,7 +492,9 @@ class FuncResultStack {
492
492
void CompleteTypeIfFunctionResult (Symbol &);
493
493
494
494
FuncInfo *Top () { return stack_.empty () ? nullptr : &stack_.back (); }
495
- FuncInfo &Push (const Scope &scope) { return stack_.emplace_back (scope); }
495
+ FuncInfo &Push (const Scope &scope, SourceName at) {
496
+ return stack_.emplace_back (scope, at);
497
+ }
496
498
void Pop ();
497
499
498
500
private:
@@ -3799,11 +3801,13 @@ bool SubprogramVisitor::Pre(const parser::PrefixSpec &x) {
3799
3801
if (const auto *parsedType{std::get_if<parser::DeclarationTypeSpec>(&x.u )}) {
3800
3802
if (FuncResultStack::FuncInfo * info{funcResultStack ().Top ()}) {
3801
3803
if (info->parsedType ) { // C1543
3802
- Say (currStmtSource ().value ( ),
3804
+ Say (currStmtSource ().value_or (info-> source ),
3803
3805
" FUNCTION prefix cannot specify the type more than once" _err_en_US);
3804
3806
} else {
3805
3807
info->parsedType = parsedType;
3806
- info->source = currStmtSource ();
3808
+ if (auto at{currStmtSource ()}) {
3809
+ info->source = *at;
3810
+ }
3807
3811
}
3808
3812
} else {
3809
3813
Say (currStmtSource ().value (),
@@ -3978,6 +3982,9 @@ bool SubprogramVisitor::Pre(const parser::FunctionStmt &) {
3978
3982
FuncResultStack::FuncInfo &info{DEREF (funcResultStack ().Top ())};
3979
3983
CHECK (!info.inFunctionStmt );
3980
3984
info.inFunctionStmt = true ;
3985
+ if (auto at{currStmtSource ()}) {
3986
+ info.source = *at;
3987
+ }
3981
3988
return BeginAttrs ();
3982
3989
}
3983
3990
bool SubprogramVisitor::Pre (const parser::EntryStmt &) { return BeginAttrs (); }
@@ -4507,7 +4514,7 @@ Symbol &SubprogramVisitor::PushSubprogramScope(const parser::Name &name,
4507
4514
symbol->set (subpFlag);
4508
4515
PushScope (Scope::Kind::Subprogram, symbol);
4509
4516
if (subpFlag == Symbol::Flag::Function) {
4510
- funcResultStack ().Push (currScope ());
4517
+ funcResultStack ().Push (currScope (), name. source );
4511
4518
}
4512
4519
if (inInterfaceBlock ()) {
4513
4520
auto &details{symbol->get <SubprogramDetails>()};
0 commit comments