I was experimenting with pointer rank remapping, and discovered some unexpected results when the pointer and target were unlimited polymorphic. I'm not certain about the code though -- feels a bit sketchy -- however I wasn't able to find anything in the 2003 standard that excludes a polymorphic target and pointer from pointer rank remapping. The compiler doesn't complain -- only the results are wrong/unexpected. Here's the code
program main class(*), allocatable, target :: array(:) class(*), pointer :: ptr(:,:) allocate(array, source=[1,2,3,4]) ptr(1:2,1:2) => array select type (ptr) type is (integer) print *, 'expect 1 2 3 4:', ptr print *, 'expect 1 3:', ptr(1,:) print *, 'expect 2 4:', ptr(2,:) print *, 'expect 1 2:', ptr(:,1) print *, 'expect 3 4:', ptr(:,2) end select end program
The results with the 14.0.2 compiler are:
expect 1 2 3 4: 1 2 3 4 expect 1 3: 538976288 538976288 expect 2 4: 538976288 538976288 expect 1 2: 1 2 expect 3 4: 1 2
Is the compiler generating bad code, or is the code not standard and the compiler just isn't complaining (kind of a bug too)? Thoughts?