Behavior of sourced allocation

Behavior of sourced allocation

I know that there are some strict restrictions on what can appear in the source= clause of the allocate statement, but I was surprised when trying to allocate a component of a derived type via sourced allocation where a sibling component (which is allocated and defined) resulted in the following error with ifort Build 20130314: 

statN.F90(352): error #8152: Neither the ERRMSG= variable nor any part of the source expression in SOURCE= or MOLD= specifiers may be allocated in the ALLOCATE statement in which it appears.   [THIS]

	       allocate(this%binkp(1:this%p-2,2:this%p) ,source=temp(1:this%p-2,:))


this%p is already defined (it's not even allocatable) and this%binkp is the component I am trying to allocate. Simply replacing this%p by an additional variable (n = this%p) fixes the compile time error. gfortran 4.8.2 has no complaints when compiling the original code FWIW.

Does my statement violate the standard, or is this a bug?

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I will let Steve or someone familiar with the standards to resolve standard/bug issue.

Try: allocate(this%binkp(1:this%p-2,2:this%p) ,source=temp(1: ( this%p-2 ) ,:))

Jim Dempsey

It's a bug. Jim's suggestion doesn't help. I'll report it to the developers. ifort needs to be more careful as to what it is looking at regarding the rules here (F2008. page 127, paragraph 3)  Issue ID is DPD200250346.

Retired 12/31/2016

This has been fixed for a major release later this year.

Retired 12/31/2016

Thanks Steve.

Since we've now seen two other reports of this problem, the developers have agreed to put the fix into the 14.0 stream. I expect the fix to appear in Update 3.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today