The following snippet, when compiled using ifort 13.0.0, gives surprising results.
[fortran]
MODULE abc
IMPLICIT NONE
TYPE :: InnerPoly
END TYPE InnerPoly
TYPE :: Container
CLASS(InnerPoly), ALLOCATABLE :: item
END TYPE Container
TYPE :: Base
TYPE(Container), ALLOCATABLE :: cont(:)
END TYPE Base
END MODULE abc
PROGRAM OhNoNowICantGrow
USE abc
IMPLICIT NONE
CLASS(Base), ALLOCATABLE :: a
TYPE(Container), ALLOCATABLE :: tmp(:)
!****
ALLOCATE(a)
ALLOCATE(a%cont(1))
! allocate bigger, assign, swap idiom for array expansion.
ALLOCATE(tmp(SIZE(a%cont)+1))
PRINT "('size of tmp:',I0)", SIZE(tmp)
tmp(:SIZE(a%cont)) = a%cont
CALL MOVE_ALLOC(tmp, a%cont)
PRINT "('size of a%cont:',I0)", SIZE(a%cont)
END PROGRAM OhNoNowICantGrow
[/fortran]
[plain]
>ifort /check:all /warn:all /standard-semantics "OhNoNowICantGrow.f90" && "OhNoNowICantGrow.exe"
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 13.0.0.089 Build 20120731
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
-out:OhNoNowICantGrow.exe
-subsystem:console
OhNoNowICantGrow.obj
size of tmp:2
size of a%cont:1
[/plain]
Bigger examples throw access violations.
Advice on possible work arounds much appreciated - that pattern for expanding an array is in very common use in my code.
(Tips on how to post code examples in forum text also appreciated! (Later edit to give the syntax highlighting instructions a whirl.))
連結已複製
