http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55172
Bug #: 55172 Summary: ICE on invalid: gfc_variable_attr(): Bad array reference Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: abenso...@gmail.com The following test case produces and ICE with gfortran 4.8 (r193051): module gn type :: ncb end type ncb type, public :: tn class(ncb), allocatable, dimension(:) :: cb end type tn contains integer function name(self) implicit none class (tn), intent(in) :: self select type (component => self%cb(i)) end select end function name end module gn $ gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-unknown- linux-gnu/4.8.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure -- prefix=/home/abenson/Galacticus/Tools --enable-languages=c,c++,fortran -- disable-multilib --with-gmp=/home/abenson/Galacticus/Tools Thread model: posix gcc version 4.8.0 20121031 (experimental) (GCC) $ gfortran -c bug4.F90 -o bug4.o bug4.F90:14.13: end module gn 1 Internal Error at (1): gfc_variable_attr(): Bad array reference The code is invalid because the "name" function contains "implicit none" but the variable "i" used in: select type (component => self%cb(i)) is not explicitly defined. If I remove the "implicit none" or explicitly define "i" the ICE goes away. (Reported by Janus at http://gcc.gnu.org/ml/fortran/2012-11/msg00005.html): With 4.7 the ICE also occurs, but only after the correct error message: select type (component => self%cb(i)) 1 Error: Symbol 'i' at (1) has no IMPLICIT type