Skip to content

Commit 1e237b1

Browse files
authored
[flang] Catch function result that is non-pointer procedure (#164664)
A function result that is a procedure must be a procedure pointer.
1 parent 1df7f2b commit 1e237b1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ void CheckHelper::Check(const Symbol &symbol) {
472472
messages_.Say(
473473
"A function result may not also be a named constant"_err_en_US);
474474
}
475+
if (!IsProcedurePointer(symbol) && IsProcedure(symbol)) {
476+
messages_.Say(
477+
"A function result may not be a procedure unless it is a procedure pointer"_err_en_US);
478+
}
475479
}
476480
if (IsAutomatic(symbol)) {
477481
if (const Symbol * common{FindCommonBlockContaining(symbol)}) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
!RUN: %python %S/test_errors.py %s %flang_fc1
2+
3+
function good() result(pptr)
4+
procedure(), pointer :: pptr
5+
external whatever
6+
pptr => whatever
7+
end
8+
9+
function bad1() result(res1)
10+
!ERROR: A function result may not be a procedure unless it is a procedure pointer
11+
procedure() res1
12+
end
13+
14+
!ERROR: Procedure 'res2' is referenced before being sufficiently defined in a context where it must be so
15+
function bad2() result(res2)
16+
!ERROR: EXTERNAL attribute not allowed on 'res2'
17+
external res2
18+
end

0 commit comments

Comments
 (0)