URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gfortran.dg/] [constructor_6.f90] - Rev 694
Compare with Previous | Blame | View Log
! { dg-do run }!! PR fortran/39427!! Contributed by Norman S. Clerman (in PR fortran/45155)!! Constructor test case!!module test_cntinteger, public, save :: my_test_cnt = 0end module test_cntmodule Rationaluse test_cntimplicit noneprivatetype, public :: rational_tinteger :: n = 0, id = 1containsprocedure, nopass :: Construct_rational_tprocedure :: Print_rational_tprocedure, private :: Rational_t_initgeneric :: Rational_t => Construct_rational_tgeneric :: print => Print_rational_tend type rational_tcontainsfunction Construct_rational_t (message_) result (return_type)character (*), intent (in) :: message_type (rational_t) :: return_type! print *, trim (message_)if (my_test_cnt /= 1) call abort()my_test_cnt = my_test_cnt + 1call return_type % Rational_t_initend function Construct_rational_tsubroutine Print_rational_t (this_)class (rational_t), intent (in) :: this_! print *, "n, id", this_% n, this_% idif (my_test_cnt == 0) thenif (this_% n /= 0 .or. this_% id /= 1) call abort ()else if (my_test_cnt == 2) thenif (this_% n /= 10 .or. this_% id /= 0) call abort ()elsecall abort ()end ifmy_test_cnt = my_test_cnt + 1end subroutine Print_rational_tsubroutine Rational_t_init (this_)class (rational_t), intent (in out) :: this_this_% n = 10this_% id = 0end subroutine Rational_t_initend module Rationalmodule Temp_nodeuse test_cntimplicit noneprivatereal, parameter :: NOMINAL_TEMP = 20.0type, public :: temp_node_treal :: temperature = NOMINAL_TEMPinteger :: id = 1containsprocedure :: Print_temp_node_tprocedure, private :: Temp_node_t_initgeneric :: Print => Print_temp_node_tend type temp_node_tinterface temp_node_tmodule procedure Construct_temp_node_tend interfacecontainsfunction Construct_temp_node_t (message_) result (return_type)character (*), intent (in) :: message_type (temp_node_t) :: return_type!print *, trim (message_)if (my_test_cnt /= 4) call abort()my_test_cnt = my_test_cnt + 1call return_type % Temp_node_t_initend function Construct_temp_node_tsubroutine Print_temp_node_t (this_)class (temp_node_t), intent (in) :: this_! print *, "temp, id", this_% temperature, this_% idif (my_test_cnt == 3) thenif (this_% temperature /= 20 .or. this_% id /= 1) call abort ()else if (my_test_cnt == 5) thenif (this_% temperature /= 10 .or. this_% id /= 0) call abort ()elsecall abort ()end ifmy_test_cnt = my_test_cnt + 1end subroutine Print_temp_node_tsubroutine Temp_node_t_init (this_)class (temp_node_t), intent (in out) :: this_this_% temperature = 10.0this_% id = 0end subroutine Temp_node_t_initend module Temp_nodeprogram Struct_overuse test_cntuse Rational, only : rational_tuse Temp_node, only : temp_node_timplicit nonetype (rational_t) :: sample_rational_ttype (temp_node_t) :: sample_temp_node_t! print *, "rational_t"! print *, "----------"! print *, ""!! print *, "after declaration"if (my_test_cnt /= 0) call abort()call sample_rational_t % printif (my_test_cnt /= 1) call abort()sample_rational_t = sample_rational_t % rational_t ("using override")if (my_test_cnt /= 2) call abort()! print *, "after override"! call print (sample_rational_t)! call sample_rational_t % print ()call sample_rational_t % printif (my_test_cnt /= 3) call abort()! print *, "sample_t"! print *, "--------"! print *, ""!! print *, "after declaration"call sample_temp_node_t % printif (my_test_cnt /= 4) call abort()sample_temp_node_t = temp_node_t ("using override")if (my_test_cnt /= 5) call abort()! print *, "after override"! call print (sample_rational_t)! call sample_rational_t % print ()call sample_temp_node_t % printif (my_test_cnt /= 6) call abort()end program Struct_over! { dg-final { cleanup-modules "test_cnt rational temp_node" } }
