[flang-commits] [flang] [FLANG]Added support for procedure pointer returning polymorphic type (PR #176695)
via flang-commits
flang-commits at lists.llvm.org
Sun Jan 18 22:15:32 PST 2026
https://github.com/ShashwathiNavada created https://github.com/llvm/llvm-project/pull/176695
Flang compiler was throwing error for below declaration.
` procedure(class(derived_type()), pointer :: ptr
`
This should be valid according to section [15.4.3.6](https://j3-fortran.org/doc/year/25/25-007r1.pdf)
The error message is shown below.
```
error: CLASS entity 'x10' must be a dummy argument, allocatable, or object pointer
procedure(class(easy)),pointer, nopass :: X10 ! ok
^^^
```
This patch allows procedure pointers to have polymorphic (CLASS) type.
The implementation adds an exception in `CheckSymbolType() ` to allow polymorphic
types for procedure pointers while explicitly excluding those with the ` EXTERNAL `
attribute.
>From 889a7c2f6aedec3b148f8341b000c8b6dd5e0e6b Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Fri, 16 Jan 2026 05:01:30 -0600
Subject: [PATCH] Added support for procedure pointer returning polymorphic
type
---
flang/lib/Semantics/check-declarations.cpp | 7 ++++++-
flang/test/Semantics/declarations09.f90 | 9 +++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Semantics/declarations09.f90
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 684c1dcc98fa3..df4280d179e1a 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -3860,7 +3860,12 @@ void CheckHelper::CheckSymbolType(const Symbol &symbol) {
} else if (IsPointer(relevant) && !IsProcedure(relevant)) {
// object pointers are always ok
} else if (auto dyType{evaluate::DynamicType::From(relevant)}) {
- if (dyType->IsPolymorphic() && !dyType->IsAssumedType() &&
+ if (IsProcedurePointer(symbol) && !symbol.attrs().test(Attr::EXTERNAL) &&
+ dyType->IsPolymorphic() && !result) {
+ // Procedure pointers are allowed to have polymorphic (CLASS) type.
+ // However, declarations like "CLASS(...), EXTERNAL, POINTER :: proc"
+ // are also classified as procedure pointers and must be excluded.
+ } else if (dyType->IsPolymorphic() && !dyType->IsAssumedType() &&
!(IsDummy(symbol) && !IsProcedure(relevant))) { // C708
messages_.Say(
"CLASS entity '%s' must be a dummy argument, allocatable, or object pointer"_err_en_US,
diff --git a/flang/test/Semantics/declarations09.f90 b/flang/test/Semantics/declarations09.f90
new file mode 100644
index 0000000000000..ef01ea3131872
--- /dev/null
+++ b/flang/test/Semantics/declarations09.f90
@@ -0,0 +1,9 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+program test
+ type :: easy
+ integer :: i
+ end type
+ type :: check
+ procedure(class(easy)),pointer, nopass :: X10 !ok
+ end type
+end program
\ No newline at end of file
More information about the flang-commits
mailing list