Pass-by-value Optional arguments

While programming something recently, I used the VALUE attribute on an optional argument without thinking much about it. In retrospect its probably an odd choice, but I can’t see any reason it would be invalid. However the resulting code, when combined with an allocatable array, causes segfaults under several compilers, in particular intel 2022 and ifx 2023. 2025 seems to have fixed it, and gfortran seems to handle it fine. Is this invalid, or is it a compiler bug? I would guess both the allocatable and the optional are inserting some extra status info and the two are colliding.

mre.f90 (442 Bytes)

I think the code is correct. The status of the optional argument is passed on to the routines that are called within the routine that has it as a dummy argument. It used to be invalid, that I am sure of, and in recent revisions of the standard this has been added. Unless of course I remember this feature wrongly.

1 Like

I would need to look up the details, but there are some situations where an unallocated actual argument will test as a not present, optional, dummy argument.