Up to revision r263781, gfortran compiles the following test (pr71764 comment 3) module sqlite3_primitive use iso_c_binding, only: c_funptr end module sqlite3_primitive module fsqlite_runtime use sqlite3_primitive use, intrinsic :: iso_c_binding, only : c_null_funptr, c_funptr implicit none contains subroutine fsqlite_exec type(c_funptr) to_cb to_cb = c_null_funptr end subroutine end module Starting at r263782, I get the error pr71764_1.f90:7:6: 7 | use sqlite3_primitive | 1 Error: Derived type 'c_funptr' at (1) has not been declared Is this expected? If no, I’ll file a new PR. If yes, why (the error message is quite confusing)? I also get the same error with the first test in pr71764 comment 4, but not with the other variants.
Reduced test case: module m1 use iso_c_binding, only: c_funptr end module module m2 use m1 use iso_c_binding end module
Draft patch: diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ded27624283..ea0ce800743 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -14245,7 +14245,7 @@ resolve_fl_derived (gfc_symbol *sym) &sym->declared_at)) return false; - if (sym->components == NULL && !sym->attr.zero_comp) + if (sym->components == NULL && !sym->attr.zero_comp && !sym->attr.use_assoc) { gfc_error ("Derived type %qs at %L has not been declared", sym->name, &sym->declared_at);
(In reply to janus from comment #2) > Draft patch: Regtests cleanly on x86_64-linux-gnu.
Author: janus Date: Tue Sep 11 17:44:04 2018 New Revision: 264214 URL: https://gcc.gnu.org/viewcvs?rev=264214&root=gcc&view=rev Log: fix PR 87172 2018-09-11 Janus Weil <janus@gcc.gnu.org> PR fortran/87172 * resolve.c (resolve_fl_derived): If a type has the 'use_assoc' attribute, then it was declared in another module, so there should be no error that it has not been declared. 2018-09-11 Janus Weil <janus@gcc.gnu.org> PR fortran/87172 * gfortran.dg/iso_c_binding_only_2.f90: New test case. Added: trunk/gcc/testsuite/gfortran.dg/iso_c_binding_only_2.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
Fixed with r264214. Closing.