URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gfortran.dg/] [class_defined_operator_1.f03] - Rev 694
Compare with Previous | Blame | View Log
! { dg-do run }! Test the fix for PR42385, in which CLASS defined operators! compiled but were not correctly dynamically dispatched.!! Contributed by Janus Weil <janus@gcc.gnu.org>!module foo_moduleimplicit noneprivatepublic :: footype :: foointeger :: foo_xcontainsprocedure :: times => times_fooprocedure :: assign => assign_foogeneric :: operator(*) => timesgeneric :: assignment(=) => assignend typecontainsfunction times_foo(this,factor) result(product)class(foo) ,intent(in) :: thisclass(foo) ,allocatable :: productinteger, intent(in) :: factorallocate (product, source = this)product%foo_x = -product%foo_x * factorend functionsubroutine assign_foo(lhs,rhs)class(foo) ,intent(inout) :: lhsclass(foo) ,intent(in) :: rhslhs%foo_x = -rhs%foo_xend subroutineend modulemodule bar_moduleuse foo_module ,only : fooimplicit noneprivatepublic :: bartype ,extends(foo) :: barinteger :: bar_xcontainsprocedure :: times => times_barprocedure :: assign => assign_barend typecontainssubroutine assign_bar(lhs,rhs)class(bar) ,intent(inout) :: lhsclass(foo) ,intent(in) :: rhsselect type(rhs)type is (bar)lhs%bar_x = rhs%bar_xlhs%foo_x = -rhs%foo_xend selectend subroutinefunction times_bar(this,factor) result(product)class(bar) ,intent(in) :: thisinteger, intent(in) :: factorclass(foo), allocatable :: productselect type(this)type is (bar)allocate(product,source=this)select type(product)type is(bar)product%bar_x = 2*this%bar_x*factorend selectend selectend functionend moduleprogram mainuse foo_module ,only : foouse bar_module ,only : barimplicit nonetype(foo) :: unitftype(bar) :: unitb! foo's assign negates, whilst its '*' negates and mutliplies.unitf%foo_x = 1call rescale(unitf, 42)if (unitf%foo_x .ne. 42) call abort! bar's assign negates foo_x, whilst its '*' copies foo_x! and does a multiply by twice factor.unitb%foo_x = 1unitb%bar_x = 2call rescale(unitb, 3)if (unitb%bar_x .ne. 12) call abortif (unitb%foo_x .ne. -1) call abortcontainssubroutine rescale(this,scale)class(foo) ,intent(inout) :: thisinteger, intent(in) :: scalethis = this*scaleend subroutineend program! { dg-final { cleanup-modules "bar_module foo_module" } }
