We are developing object oriented examples for our next book and have hit a
compiler bug with the following short program. 

program polymorphic

use shape_module
use circle_module
use rectangle_module

implicit none

type shape_w
  class (shape_type) , allocatable :: shape_v
end type shape_w

type (shape_w) , dimension(3) :: p

  print *,' shape '

  p(1)%shape_v=shape_type(10,20)
  call p(1)%shape_v%draw()

  print *,' circle '

  p(2)%shape_v=circle_type(100,200,300)
  call p(2)%shape_v%draw()

  print *,' rectangle '

  p(3)%shape_v=rectangle_type(1000,2000,3000,4000)
  call p(3)%shape_v%draw()

end program polymorphic

The following example program compiles and runs.

program polymorphic

use shape_module
use circle_module
use rectangle_module

implicit none

class (shape_type)     , allocatable :: p

  allocate(shape_type :: p)

  print *,' ** shape **'

  p=shape_type(10,20)
  call p%draw()

  print *,' ** circle **'

  p=circle_type(100,200,300)
  call p%draw()

  print *,' ** rectangle **'

  p=rectangle_type(1000,2000,3000,4000)
  call p%draw()

end program polymorphic

Here is the rest of the information requested in the bug report
document.

gcc version
-----------

c:\document\fortran\newbook\examples\ch32>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/program files
(x86)/gfortran/bin/../libexec/gcc/i586-pc-mingw32/4.6.0/lto-wrapper.exe
Target: i586-pc-mingw32
Configured with: ../gcc-trunk/configure --prefix=/mingw
--enable-languages=c,fortran --with-gmp=/home/brad/gfortran/dependencies -
-disable-werror --enable-threads --disable-nls --build=i586-pc-mingw32
--enable-libgomp --disable-shared --disable-win32-registry
--with-dwarf2 --disable-sjlj-exceptions : (reconfigured) ../gcc-trunk/configure
--prefix=/mingw --enable-languages=c,fortran --wit
h-gmp=/home/brad/gfortran/dependencies --disable-werror --enable-threads
--disable-nls --build=i586-pc-mingw32 --enable-libgomp --
disable-shared --disable-win32-registry --with-dwarf2 --disable-sjlj-exceptions
Thread model: win32
gcc version 4.6.0 20100524 (experimental) [trunk revision 159774] (GCC)

Hardware and Operating system
-----------------------------

The information below is from the Intel
CPU id utility.

++++++++++++++++++++++++++++++++++++++++++

Intel(R) Processor Identification Utility
Version: 4.22.20100224
Time Stamp: 2010/06/08 09:48:20
Operating System: 6.0-6002-Service Pack 2
Number of processors in system: 1
Current processor: #1
Active cores per processor: 4
Disabled cores per processor: 0
Processor Name: Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz

stuff deleted

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The system is running 

  Windows Vista Home Premium SP2 - 64 Bit.

gcc build options
=================

I did not build it I just took the gfortran executable
from the download site.

Compiler command line
=====================


c:\document\fortran\newbook\examples\ch32>gfortran shape_p.f90 circle_p.f90
rectangle_p.f90 polymorph_array.f90
polymorph_array.f90: In function 'polymorphic':
polymorph_array.f90:18:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Do you want the shape_p.f90, circle_p.f90 and rectangle_p.f90
source files?


-- 
           Summary: polymorphic object oriented example
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at rhymneyconsulting dot co dot uk


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44465

Reply via email to