Consider the following code
program assoc_ptr integer, pointer :: p, q, r allocate(p) allocate(q) p = 1 q = 2 associate(x => p, y => q) print *, x, y q => p y = 5 q = 6 print *, x, y allocate(r) deallocate(p) p => r x = 3 p = 4 print *, x, y end associate end program assoc_ptr
Is this allowed and standard-conformant? My gut-feeling is that this is simply wrong code. With ifort (19 beta, with and without optimisation) the output is:
So in both cases, the association of y with q and of x with p are lost. In general this should lead to a SEGFAULT in more complex cases. Nevertheless, this looks like a bad pitfall if pointers are buried within complex derived types whose components might be reallocated in some subroutines...