https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64927
Bug ID: 64927 Summary: [4.7/4.8 Regression] Surprising error with -Wsurprising (-Wall) and TRANSFER + C_ASSOCIATED Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: anlauf at gmx dot de The following error occurs with 4.7 and 4.8, but not with 4.6 or 4.9. The error is slightly annoying since -Wsurprising is automatically enabled by -Wall, and it was a try-and-error by a colleague to trace the problem to -Wsurprising. The error shows up only if both indicated code lines with TRANSFER and C_ASSOCIATED are active, commenting out any of them makes the error disappear. The dump-tree for 4.8 and 4.9 does not show any difference if -Wno-surprising is set. The error is bogus. > cat gfcbug130.f90 ! gfortran -c gfcbug130.f90 -Wall ! false error, compare -Wsurprising vs. -Wno-surprising module surprise use iso_c_binding implicit none TYPE t_pointer TYPE(c_ptr) :: cptr END TYPE t_pointer contains SUBROUTINE get_pointer (ibuf) INTEGER, INTENT(IN) :: ibuf(:) TYPE(t_pointer) :: zp ! Error disappears if any line is commented out: zp = TRANSFER (ibuf, zp) IF (C_ASSOCIATED (zp% cptr)) Print *, "OK" END SUBROUTINE get_pointer end module surprise > gfc-48 -c gfcbug130.f90 -Wall gfcbug130.f90:16.22: IF (C_ASSOCIATED (zp% cptr)) Print *, "OK" 1 Error: Type mismatch in argument 'c_ptr_1' at (1); passed INTEGER(4) to TYPE(c_ptr) > gfc-48 -c gfcbug130.f90 -Wall -Wno-surprising The problem does not occur in 4.9. If there is an easy fix for 4.8, could it be backported? (I understand that the 4.7 branch is already closed.) Thanks, Harald