Skip to content

Commit 2a93cd9

Browse files
committed
Add ASSERT_() a legal synonym for __ASSERT_()
Two consecutive underscores in a name is undefined behavior in C++; a single leading underscore is undefined behavior in C in the global name space.
1 parent 2b8cbf5 commit 2a93cd9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

handy.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,22 @@ don't, so that you can portably take advantage of this C99 feature.
350350

351351
/*
352352
=for apidoc_section $directives
353-
=for apidoc Am||__ASSERT_|bool expr
353+
=for apidoc Am||ASSERT_|bool expr
354+
=for apidoc_item D|| __ASSERT_
354355
355-
This is a helper macro to avoid preprocessor issues, replaced by nothing
356-
unless under DEBUGGING, where it expands to an assert of its argument,
357-
followed by a comma (hence the comma operator). If we just used a straight
358-
assert(), we would get a comma with nothing before it when not DEBUGGING.
356+
These are synonymous.
357+
358+
They are helper macros to avoid preprocessor issues, replaced by nothing
359+
unless under DEBUGGING, where they expand to an assert() of their argument,
360+
followed by a comma (hence the trailing underscore in their names, and the
361+
comma operators in their expansions). If we just used a straight assert(), we
362+
would get a comma with nothing before it when not DEBUGGING.
363+
364+
C<ASSERT_> is preferred, as C<__ASSERT_> actually creates undefined behavior in
365+
C and C++, because the leading underscores yield a name form that is reserved
366+
for the compiler's use. See L<perlhacktips/Choosing legal symbol names>.
367+
368+
C<__ASSERT_> is kept only for backwards compatibility.
359369
360370
=cut
361371
@@ -365,10 +375,11 @@ detects that and gets all excited. */
365375

366376
#if defined(DEBUGGING) && !defined(__COVERITY__) \
367377
&& ! defined(PERL_SMALL_MACRO_BUFFER)
368-
# define __ASSERT_(statement) assert(statement),
378+
# define ASSERT_(statement) assert(statement),
369379
#else
370-
# define __ASSERT_(statement)
380+
# define ASSERT_(statement)
371381
#endif
382+
#define __ASSERT_(statement) ASSERT_(statement)
372383

373384
/*
374385
=for apidoc_section $SV

0 commit comments

Comments
 (0)