The following code fails to compile with gcc version 4.5.0-pre9999 20100224
(experimental) rev. 157053. However, if lines 22, 23 and 27 (i.e. 'select
type(x)', 'class is (myType)', and 'end select') are removed it compiles fine
and the executable gives the expected output '2.0000 1.0000'.

Source compiled with ifort v. 11.1 behaves as expected with 'select type'
construct included. 

$ cat test.f90 && gfortran test.f90                             
program testPure
implicit none
type :: myType
    real :: a,b
end type myType
type(myType),target :: y
class(myType),pointer :: x

x=>y
x%a=1.
x%b=2.
call swap(x)
print *, x%a,x%b

contains

pure subroutine swap(x)
implicit none
class(myType), intent(inout) :: x
real :: work

select type(x)
class is (myType)
    work=x%a
    x%a=x%b
    x%b=work
end select
end subroutine swap
end program testPure
test.f90:25.4:

    x%a=x%b
    1
Error: Cannot assign to variable 'tmp$class$mytype' in PURE procedure at (1)
test.f90:26.4:

    x%b=work
    1
Error: Cannot assign to variable 'tmp$class$mytype' in PURE procedure at (1)

********************
Now with 'select type' construct removed


$ cat test.f90 && gfortran test.f90 && ./a.out                   
--(Wed,Feb24)--
program testPure
implicit none
type :: myType
    real :: a,b
end type myType
type(myType),target :: y
class(myType),pointer :: x

x=>y
x%a=1.
x%b=2.
call swap(x)
print *, x%a,x%b

contains

pure subroutine swap(x)
implicit none
class(myType), intent(inout) :: x
real :: work

    work=x%a
    x%a=x%b
    x%b=work
end subroutine swap
end program testPure

   2.0000000       1.0000000


-------------------------------------
gcc configure options:
$ gcc -v
gcc -v                                                          
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.0-pre9999/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.0-pre9999/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-4.5.0_pre9999/work/gcc-4.5.0-9999/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.0-pre9999
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0-pre9999/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.0-pre9999
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.0-pre9999/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.0-pre9999/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.0-pre9999/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --with-ppl --with-cloog --enable-nls
--without-included-gettext --with-system-zlib --disable-checking
--disable-werror --enable-secureplt --enable-multilib --enable-libmudflap
--disable-libssp --enable-libgomp --enable-cld
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.0-pre9999/python
--disable-libgcj --enable-languages=c,c++,fortran --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo SVN'
--enable-lto --disable-checking
Thread model: posix
gcc version 4.5.0-pre9999 20100224 (experimental) rev. 157053 (Gentoo SVN)


-- 
           Summary: gfortran rejects pure procedure with select type
                    construct
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: haymaker at mail dot utexas dot edu
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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

Reply via email to