Static assert in Fortran

You can assign a negative integer as kind parameter to cause compilation to fail. Here is an example related to detecting quad precision: Compile time detection of extended-double or quad precision - #8 by ivanpribec

Here is an example how you may apply this to storage size:

program assert
use iso_c_binding, only: c_double
integer, parameter :: fortran_dp = kind(1.0d0)
integer, parameter :: wp = merge(fortran_dp, -1, &
    storage_size(1.0_fortran_dp) == storage_size(1.0_c_double))
real(wp) :: foo
foo = 1.0_wp
print *, foo
end program