[gcc r12-9309] Fortran: procedures with BIND(C) attribute require explicit interface [PR85877]
Harald Anlauf
anlauf@gcc.gnu.org
Wed Mar 22 18:00:08 GMT 2023
https://gcc.gnu.org/g:b6bef857c1e8bde9df2ba53a708ecffded316ec8
commit r12-9309-gb6bef857c1e8bde9df2ba53a708ecffded316ec8
Author: Harald Anlauf <anlauf@gmx.de>
Date: Fri Mar 17 22:24:49 2023 +0100
Fortran: procedures with BIND(C) attribute require explicit interface [PR85877]
gcc/fortran/ChangeLog:
PR fortran/85877
* resolve.cc (resolve_fl_procedure): Check for an explicit interface
of procedures with the BIND(C) attribute (F2018:15.4.2.2).
gcc/testsuite/ChangeLog:
PR fortran/85877
* gfortran.dg/pr85877.f90: New test.
(cherry picked from commit 5426ab34643d9e6502f3ee572891a03471fa33ed)
Diff:
---
gcc/fortran/resolve.cc | 10 ++++++++++
gcc/testsuite/gfortran.dg/pr85877.f90 | 25 +++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 744eebbb9b4..14baf63e6af 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -13625,6 +13625,16 @@ check_formal:
}
}
}
+
+ /* F2018:15.4.2.2 requires an explicit interface for procedures with the
+ BIND(C) attribute. */
+ if (sym->attr.is_bind_c && sym->attr.if_source == IFSRC_UNKNOWN)
+ {
+ gfc_error ("Interface of %qs at %L must be explicit",
+ sym->name, &sym->declared_at);
+ return false;
+ }
+
return true;
}
diff --git a/gcc/testsuite/gfortran.dg/pr85877.f90 b/gcc/testsuite/gfortran.dg/pr85877.f90
new file mode 100644
index 00000000000..d8f08cbd210
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr85877.f90
@@ -0,0 +1,25 @@
+! { dg-do compile }
+! PR fortran/85877
+! A procedure with the bind(c) attribute shall have an explicit interface
+! Contributed by G. Steinmetz
+
+function f() bind(c)
+ f = 42.
+end
+
+subroutine p
+ bind(c) f ! { dg-error "must be explicit" }
+ x = f()
+end
+
+function g() bind(c)
+ g = 42.
+end
+
+subroutine s
+ interface
+ function g() bind(c)
+ end function g
+ end interface
+ x = g()
+end
More information about the Gcc-cvs
mailing list