j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
175 stars 14 forks source link

Make cmplx with non-default real arguments and unspecified kind obsolescent #237

Open Beliavsky opened 2 years ago

Beliavsky commented 2 years ago

I suggest that when the x and y arguments of cmplx are both of a real type other than default real or that when only x is present and is not a default real that it be obsolescent to not specify the kind argument of cmplx. The expression

cmplx(1.0d0,1.0d0)

does not produce a double precision complex number, although a casual reader may think it does. It's anomalous, because other intrinsics such as sin or sum return reals of the same kind as the argument. To avoid errors one should be forced to write

cmplx(1.0d0,1.0d0,kind=some_kind)

It will be not be obsolescent to write

cmplx(1.0,1.0)

since no silent conversion is performed here.

Starting from scratch, cmplx(1.0d0,1.0d0) should return a double precision complex value, but I am wary of changing the meaning of valid code.

certik commented 2 years ago

Indeed. I think at the very least, compilers should warn about this.