Bug 87172 - [9 Regression] Spurious "Derived type 'c_funptr' at (1) has not been declared" error after r263782
Summary: [9 Regression] Spurious "Derived type 'c_funptr' at (1) has not been declared...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P4 normal
Target Milestone: 9.0
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-08-31 15:37 UTC by Dominique d'Humieres
Modified: 2018-09-12 09:16 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 8.2.0
Known to fail: 9.0
Last reconfirmed: 2018-08-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2018-08-31 15:37:30 UTC
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.
Comment 1 janus 2018-08-31 17:14:04 UTC
Reduced test case:


module m1
   use iso_c_binding, only: c_funptr
end module

module m2
  use m1
  use iso_c_binding
end module
Comment 2 janus 2018-08-31 18:34:07 UTC
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);
Comment 3 janus 2018-08-31 19:07:51 UTC
(In reply to janus from comment #2)
> Draft patch:

Regtests cleanly on x86_64-linux-gnu.
Comment 4 janus 2018-09-11 17:44:36 UTC
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
Comment 5 janus 2018-09-12 09:16:37 UTC
Fixed with r264214. Closing.