Skip to content

Commit

Permalink
handy.h: Skip non-ptr assertion on old gcc's
Browse files Browse the repository at this point in the history
See #18655, which this fixes.
  • Loading branch information
khwilliamson committed Aug 25, 2021
1 parent 296969d commit de40ad3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions handy.h
Expand Up @@ -1424,9 +1424,16 @@ or casts
# define WIDEST_UTYPE U32
#endif

/* Use this, where there could be some confusion, as a static assert in macros
* to make sure that a parameter isn't a pointer. */
#define ASSERT_NOT_PTR(x) ((x) | 0)
/* Where there could be some confusion, use this as a static assert in macros
* to make sure that a parameter isn't a pointer. But some compilers can't
* handle this. The only one known so far that doesn't is gcc 3.3.6; the check
* below isn't thorough for such an old compiler, so may have to be revised if
* experience so dictates. */
#if ! PERL_IS_GCC || PERL_GCC_VERSION_GT(3,3,6)
# define ASSERT_NOT_PTR(x) ((x) | 0)
#else
# define ASSERT_NOT_PTR(x) (x)
#endif

/* FITS_IN_8_BITS(c) returns true if c doesn't have a bit set other than in
* the lower 8. It is designed to be hopefully bomb-proof, making sure that no
Expand All @@ -1443,7 +1450,7 @@ or casts
/* The '| 0' part ensures a compiler error if c is not integer (like e.g., a
* pointer) */
# define FITS_IN_8_BITS(c) ( (sizeof(c) == 1) \
|| ((WIDEST_UTYPE)((c) | 0) == ((U8)(c))))
|| ((WIDEST_UTYPE) ASSERT_NOT_PTR(c)) == ((U8)(c)))
#else
# define FITS_IN_8_BITS(c) (1)
#endif
Expand Down

0 comments on commit de40ad3

Please sign in to comment.