@@ -5109,6 +5109,45 @@ Gid_t getegid (void);
51095109 Perl_deb (aTHX_ " %s scope %ld (savestack=%ld) at %s:%d\n " , \
51105110 where, (long )PL_scopestack_ix, (long )PL_savestack_ix, \
51115111 __FILE__, __LINE__));
5112+ /*
5113+ =for apidoc_section $directives
5114+ =for apidoc Am|void|assert_|bool expr
5115+ =for apidoc_item | |__ASSERT_
5116+
5117+ These are synonymous, used to wrap the libc C<assert()> call in comma
5118+ expressions in macro expansions, but you probably don't want to use them nor
5119+ plain C<assert>; read on.
5120+
5121+ In DEBUGGING builds, each expands to an assert of its argument, followed by
5122+ a comma. (That is what the trailing underscore signifies.)
5123+
5124+ In non-DEBUGGING builds, each expands to nothing.
5125+
5126+ They thus can be used to string together a bunch of asserts in a comma
5127+ expression that is syntactically valid in either type of build.
5128+
5129+ NOTE, however, use of these (and plain C<assert()>) is discouraged in a macro.
5130+ This is because their usual use is to validate some of the arguments to that
5131+ macro. That will likely lead to the evaluation of those arguments more than
5132+ once during the macro expansion. If such an argument is an expression with
5133+ side effects, the behavior of the macro will differ between DEBUGGING and
5134+ non-DEBUGGING builds.
5135+
5136+ And, they are necessary only on platforms where the libc C<assert()> expands to
5137+ nothing when not in a DEBUGGING build. There should be no such platforms now
5138+ in existence, as the C89 standard forbids that, and Perl requires at least C99.
5139+ So, you can just use plain C<assert>, and say S<C<assert(...), assert(...),>>
5140+ and everything will compile (and will work if none of the arguments to the
5141+ asserts is an expression with side effects).
5142+
5143+ These macros are retained for backward compatibility.
5144+
5145+ Do NOT use C<__ASSERT_>. A name with two leading underscores followed by a
5146+ capital letter is reserved for the use of the compiler and libc in some
5147+ contexts in C, and in all contexts in C++.
5148+
5149+ =cut
5150+ */
51125151
51135152/* Keep the old croak based assert for those who want it, and as a fallback if
51145153 the platform is so heretically non-ANSI that it can't assert. */
@@ -5128,9 +5167,11 @@ Gid_t getegid (void);
51285167 STRINGIFY (what), (line_t ) __LINE__), \
51295168 (void ) 0 ))
51305169# define assert_ (what ) assert (what),
5170+ # define __ASSERT_ (statement ) assert (statement),
51315171#else
51325172# define Perl_assert (what ) ((void ) 0 )
51335173# define assert_ (what )
5174+ # define __ASSERT_ (statement )
51345175#endif
51355176
51365177struct ufuncs {
0 commit comments