Traits/interfaces in Fortran?

As has been discussed in many forums, target, intent(in) is not a reliable library solution, particularly due to automatic targeting semantics in the standard.

Fortranners may consider pointer, intent(in) instead with such use cases. The actual objects (e.g., a, b in the OP’s latest example) can thus be ALLOCATABLE (or nonallocatable) but with the TARGET attribute and that is a safer approach.

Honestly, I failed to implement this with a pointer (GCC complained when I tried passing anything but class(*) pointer as an actual argument even for pointer, intent(in)). But of course, if there was a way to prevent user from passing anything which is not a pointer would be great.