Bug 45155 - implemention of structure constructor override using a generic interface
Summary: implemention of structure constructor override using a generic interface
Status: RESOLVED DUPLICATE of bug 39427
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-31 22:14 UTC by Norman S. Clerman
Modified: 2010-08-01 07:25 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Norman S. Clerman 2010-07-31 22:14:40 UTC
gfortran tech support:

 Following the body of this report is a short program that tests two different ways to override a structure constructor. When I compile it using 

GNU Fortran (GCC) 4.6.0 20100606 (experimental) [trunk revision 160350]

gfortran reports the following errors:

struct_overP.f90:59.23:

  interface temp_node_t
                       1
Error: DERIVED attribute of 'temp_node_t' conflicts with PROCEDURE attribute at (1)
struct_overP.f90:60.21:

    module procedure Construct_temp_node_t
                     1
Error: MODULE PROCEDURE at (1) must be in a generic module interface
struct_overP.f90:61.5:

  end interface
     1
Error: Expecting END MODULE statement at (1)
struct_overP.f90:93.35:

  use Temp_node, only : temp_node_t
                                   1
Fatal Error: Can't open module file 'temp_node.mod' for reading at (1): No such file or directory
norm@oxford:~/Elements/StructOver$ 

  I am uncertain if this represents a bug or a feature of Fortran 2003 that has yet to be added to gfortran, so I am submitting it as an enhancement.

  Thank you for you attention.

Norm

Norman S. Clerman
Consulting computer scientist


module Rational

  implicit none
  private

  type, public :: rational_t
    integer :: n = 0, id = 1
  contains
    procedure, nopass :: Construct_rational_t
    procedure :: Print_rational_t
    procedure, private :: Rational_t_init
    generic :: Rational_t => Construct_rational_t
    generic :: print      => Print_rational_t
  end type rational_t

contains

  function Construct_rational_t (message_) result (return_type)
    character (*), intent (in) :: message_
    type (rational_t) :: return_type

    print *, trim (message_)
    call return_type % Rational_t_init

  end function Construct_rational_t

  subroutine Print_rational_t (this_)
    class (rational_t), intent (in) :: this_

    print *, "n, id", this_% n, this_% id
  end subroutine Print_rational_t

  subroutine Rational_t_init (this_)
    class (rational_t), intent (in out) :: this_

    this_% n = 10
    this_% id = 0
    
  end subroutine Rational_t_init
  
end module Rational

module Temp_node

  implicit none
  private

  real, parameter :: NOMINAL_TEMP = 20.0

  type, public :: temp_node_t
    real :: temperature = NOMINAL_TEMP
    integer :: id = 1
  contains
    procedure :: Print_temp_node_t
    procedure, private :: Temp_node_t_init
    generic :: Print => Print_temp_node_t
  end type temp_node_t

  interface temp_node_t
    module procedure Construct_temp_node_t
  end interface

contains

  function Construct_temp_node_t (message_) result (return_type)
    character (*), intent (in) :: message_
    type (temp_node_t) :: return_type

    print *, trim (message_)
    call return_type % Temp_node_t_init

  end function Construct_temp_node_t

  subroutine Print_temp_node_t (this_)
    class (temp_node_t), intent (in) :: this_

    print *, "temp, id", this_% temperature, this_% id
  end subroutine Print_temp_node_t

  subroutine Temp_node_t_init (this_)
    class (temp_node_t), intent (in out) :: this_

    this_% temperature = 10.0
    this_% id = 0
    
  end subroutine Temp_node_t_init
  
end module Temp_node

program Struct_over

  use Rational,  only : rational_t
  use Temp_node, only : temp_node_t

  implicit none

  type (rational_t)  :: sample_rational_t
  type (temp_node_t) :: sample_temp_node_t

  print *, "rational_t"
  print *, "----------"
  print *, ""

  print *, "after declaration"
  call sample_rational_t % print

  sample_rational_t = sample_rational_t % rational_t ("using override")
  print *, "after override"
!  call print (sample_rational_t)
!  call sample_rational_t % print ()
  call sample_rational_t % print
  
  print *, "sample_t"
  print *, "--------"
  print *, ""

  print *, "after declaration"
  call sample_temp_node_t % print

  sample_temp_node_t = temp_node_t ("using override")
  print *, "after override"
!  call print (sample_rational_t)
!  call sample_rational_t % print ()
  call sample_temp_node_t % print
  
end program Struct_over
Comment 1 Tobias Burnus 2010-08-01 07:25:56 UTC

*** This bug has been marked as a duplicate of 39427 ***