Skip to content

Conversation

khwilliamson
Copy link
Contributor

@khwilliamson khwilliamson commented Aug 22, 2025

The STATIC_ASSERT macros are useful and have been stable for long enough to be made API.

This also adds STATIC_ASSERT_EXPR suitable for use in macros. It doesn't achieve parity with the others except on systems where gcc brace groups are used, falling back to less or no checking otherwise. But that's good enough to be useful and any problems will be caught when the code is attempted to be compiled on a brace group platform.

  • This set of changes requires a perldelta entry, which is included

@khwilliamson khwilliamson force-pushed the static_assert branch 2 times, most recently from 407c99c to 3c81bbd Compare August 23, 2025 13:00
@tonycoz
Copy link
Contributor

tonycoz commented Sep 1, 2025

Ok otherwise.

There are now enough items, that sorting is helpful to reading
I think these are useful and stable enough to make public
I found these useful in understanding it
These make things a bit clearer by not putting so much in each macro
This new type of a STATIC_ASSERT is used where an expression can go;
hence potentially in macro expansions.  Since it is compile-time, it
can't be used on arguments that are expressions with side effects, so
can safely be used in macros.

It has limitations however, only reaching full parity when gcc brace
groups are enabled, turning into an ASSUME which is a no-op in the worst
case.

However, most code will get compiled on a platform with gcc brace
groups, and will pass or fail at compile time; so the chances of
something bad actually getting into the field are minimal.
@khwilliamson khwilliamson changed the title Document STATIC_ASSERT; add STATIC_ASSERT_EXPR and use it Document STATIC_ASSERT; add STATIC_ASSERT_EXPR Sep 2, 2025
@khwilliamson khwilliamson merged commit e7a8320 into Perl:blead Sep 3, 2025
33 checks passed
@khwilliamson khwilliamson deleted the static_assert branch September 4, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants