https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103931
Bug ID: 103931 Summary: Type name "c_ptr" is ambiguous when iso_c_binding is imported both directly and indirectly Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: trnka at scm dot com Target Milestone: --- Created attachment 52135 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52135&action=edit full testcase demonstrating the bug Compiling the attached test case fails for me on gfortran 11.2.1 20210728 (Red Hat 11.2.1-1): $ gfortran -c gcc-ambiguous-cptr.f90 gcc-ambiguous-cptr.f90:97:19: 97 | type (C_PTR) :: context | 1 Error: Type name ‘c_ptr’ at (1) is ambiguous (Sorry for the convoluted module structure, I can't seem to reduce it further without making the issue disappear.) The issue occurs in this piece of code: subroutine HProc() use FModule use ISO_C_BINDING use GModule type (C_PTR) :: context end subroutine Here, both FModule and GModule use ISO_C_BINDING indirectly in different ways, so their module files contain c_ptr which gets picked up. Apparently, c_ptr then gets marked as ambiguous by check_for_ambiguous() in module.c:read_module() while reading GModule. After compiling it once as above to generate all the modules, you can add "-cpp -DNODEPS=1" for further testing to focus on the problematic part (using existing module files). Strangely enough, gfortran 9.3.1 20200804 compiles the test without errors when compiling everything but fails with the above error with NODEPS. gfortran 11 fails in both modes. Not sure if that counts as a regression or if it's just a random coincidence. I can bisect that if desired.