https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71592
Bug ID: 71592
Summary: Add some facilities for compile-time check
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: heresy-me at hotmail dot com
Target Milestone: ---
There are many occasion that to do some compile-time check if we need. For
example, I write my own sqrt function that it may check its parameter should
greater than or equal to zero at compile-time when it is compile-time
evaluated. such as:
function mysqrt(r)
real :: mysqrt
$!assert static(r >= 0.0, "radicand is negative.")
real, intent(in) :: r
end function
just normally likes the compiler behavior.
it also may specify like "!$assert dynamic", "!$assert static_dynamic"
So I need not to fix the obivous compile-time until the program debug. Just
because I know that the C/C++ compiler has been added a standard static_assert
or _Static_assert keyword to finish this work, the Ada language also can
specify the function precondition, then why fortran can't?
C/C++:
float mysqrt(float r) {
static_assert(r >= 0.0, "radicand is negative.");
/* ... */
}
Ada:
function mysqrt(r : Float) return Float
with Precondition => (r >= 0.0);