Note that the argument to sub must be allocatable or optional then in your example. As written the call to is_unallocated should always return .true., as it is always present, but you may get a segfault if the actual argument to sub isn’t allocated. I.e. it should be
subroutine sub(useless_var, print_this)
type(*), intent(in), optional :: useless_var(..)
character(*), intent(in) :: print_this
print *, "should be 123: '", print_this, "'"
print *, "useless_var is unallocated", is_unallocated(useless_var)
end subroutine sub
Note that type(*) is fine in this case if you don’t intend to use its value.