select type failure?

Janus Weil janus@gcc.gnu.org
Wed Feb 16 08:53:00 GMT 2011


Hi Andrew,

> Assuming that my code is valid (it is as far as I can tell, but if not I'd be
> happy to hear what I'm doing wrong) then I would expect the "select type"
> construct to execute the contents of the "type is (treeNode)" block and not
> the "class default" block.

yes, you're right. This looks like a bug in gfortran. I have reduced
your test case to the following:


module Tree_Nodes
  type treeNode
   contains
     procedure :: walk
  end type
contains
  subroutine walk (thisNode)
    implicit none
    class (treeNode) :: thisNode
    select type (thisNode)
    type is (treeNode)
       write (*,*) 'correct'
    class default
       write (*,*) 'incorrect'
    end select
  end subroutine
end module

module Merger_Trees
  use Tree_Nodes
  private
  public :: mergerTree
  type mergerTree
     type(treeNode), pointer :: baseNode
  end type
end module

module Merger_Tree_Build
  use Merger_Trees
end module

program test
  use Merger_Tree_Build
  use Tree_Nodes
  implicit none
  type(treeNode) :: node
  call node%walk ()
end program


This compiles and prints 'incorrect' at runtime. There are a number of
ways to avoid the bug and get the output 'correct':
* removing the 'private' statement
* removing the 'public' statement
* removing the 'baseNode' component
* removing the unneeded module 'merger_tree_build'
* ...

Very peculiar thing, definitely a bug. Would be great if you could
open a PR for it.

Thanks,
Janus



More information about the Fortran mailing list