https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96018
--- Comment #4 from martin.schlipf at damnthespam dot com --- Hdf5 doesn't have native support for complex datatypes, so we convert to real and write that it is a complex as an attribute. If you replace the conversion logic by an array instead of a pointer allocate(real_array(2,size(array,1),size(array,2),size(array,3))) reshape(transfer(array, real_array), shape(real_array)) it doesn't alert the behavior. I agree that the error code should be checked and in fact, I already started a merge request for that particular part. But for this bug report, I need to leave it away, because otherwise the compiler does the right thing. Finally, I reproduced it with gfortran 9.3.0 + hdf 1.12.0 and gfortran 10.0 + hdf 1.10.4. With older versions of gfortran 7.3.0 it does not appear.