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



             Bug #: 57096

           Summary: Polymorphic allocatable variable is not behaved as

                    expected

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: fortran

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: fg...@hotmail.com





Created attachment 29955

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29955

simple test program with Makefile



The global variable gA and gAp are allocatable and pointer of abstract derived

type A, respectively.



    class(A), allocatable :: gA ! polymorphic allocatable variable

    class(A), pointer :: gAp ! polymorphic pointer variable



They are allocated with the same type (A1 or A2) extends from type A and

intialized in the same way.



subroutine init(i) bind(c, name="init")

...

    if(i == 1) then

        allocate(A1::gA)

        allocate(A1::gAp)

    else

        allocate(A2::gA)

        allocate(A2::gAp)

    end if

    call gA%init()

    call gAp%init()

...



then



subroutine run() bind(c, name="run")

....

    print*, "gA%next():", gA%next()

    print*, "gA%next():", gA%next()

    print*, "gA%next():", gA%next()

    print*

    print*, "gAp%next():", gAp%next()

    print*, "gAp%next():", gAp%next()

    print*, "gAp%next():", gAp%next()

...



When they are called from a C++ program, however, they behave quitely

differently.





extern "C" {

    extern void init(int i);

    extern void run();

}



int main()

{

    init(2);

    run();

    return 0;

}



The test program output is



% ./test

 gA%next():           0

 gA%next():           0

 gA%next():           0



 gAp%next():           2

 gAp%next():           4

 gAp%next():           6



where only the pointer version behaves as expected.

Reply via email to