Skip to content

Commit 98f86c5

Browse files
committed
Update call_assert() macros to use assert_always()
This ensures that call_assert() macro invocations always respect the *current* (possibly locally defined) value of ASSERTIONS, regardless of ASSERTIONS setting used to build the assert_m module.
1 parent b911395 commit 98f86c5

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

example/invoke-via-macro.F90

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
program invoke_via_macro
44
!! Demonstrate how to invoke the 'assert' subroutine using a preprocessor macro that facilitates
55
!! the complete removal of the call in the absence of the compiler flag: -DASSERTIONS
6-
use assert_m, only : assert, intrinsic_array_t, string
7-
!! If an "only" clause is employed as above, it must include the "string" function that the
8-
!! call_assert* macros reference when transforming the code below into "assert" subroutine calls.
6+
use assert_m ! <--- this is the recommended use statement
7+
!! If an "only" clause is employed above, the symbols required by the
8+
!! macro expansion are subject to change without notice between versions.
9+
!! You have been warned!
910
implicit none
1011

1112
#if !ASSERTIONS
@@ -15,7 +16,7 @@ program invoke_via_macro
1516
print *
1617
#endif
1718

18-
! The C preprocessor will convert each call_assert* macro below into calls to the "assert" subroutine
19+
! The C preprocessor will convert each call_assert* macro below into calls that enforce the assertion
1920
! whenever the ASSERTIONS macro is defined to non-zero (e.g. via the -DASSERTIONS compiler flag).
2021
! Whenever the ASSERTIONS macro is undefined or defined to zero (e.g. via the -DASSERTIONS=0 compiler flag),
2122
! these calls will be entirely removed by the preprocessor.

include/assert_macros.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#endif
2323

2424
#if ASSERTIONS
25-
# define call_assert(assertion) call assert(assertion, "call_assert(" // STRINGIFY(assertion) // ") in file " // __FILE__ // ", line " // string(__LINE__))
26-
# define call_assert_describe(assertion, description) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__))
27-
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__), diagnostic_data)
25+
# define call_assert(assertion) call assert_always(assertion, "call_assert(" // STRINGIFY(assertion) // ") in file " // __FILE__ // ", line " // string(__LINE__))
26+
# define call_assert_describe(assertion, description) call assert_always(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__))
27+
# define call_assert_diagnose(assertion, description, diagnostic_data) call assert_always(assertion, description // " in file " // __FILE__ // ", line " // string(__LINE__), diagnostic_data)
2828
#else
2929
# define call_assert(assertion)
3030
# define call_assert_describe(assertion, description)

0 commit comments

Comments
 (0)