Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/roaring/portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ static inline uint32_t croaring_refcount_get(const croaring_refcount_t *val) {
{ 0 }
#endif

#if defined(__cplusplus)
#define CROARING_STATIC_ASSERT(x, y) static_assert(x, y)
#else
#define CROARING_STATIC_ASSERT(x, y) _Static_assert(x, y)
Comment on lines +592 to +593
Copy link
Preview

Copilot AI Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard the C branch of this macro with a check for C11 support (e.g., __STDC_VERSION__ >= 201112L) so that older C compilers without _Static_assert don’t break the build.

Suggested change
#else
#define CROARING_STATIC_ASSERT(x, y) _Static_assert(x, y)
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#define CROARING_STATIC_ASSERT(x, y) _Static_assert(x, y)
#else
#define CROARING_STATIC_ASSERT(x, y) /* static assert not supported */

Copilot uses AI. Check for mistakes.

#endif

// We need portability.h to be included first,
// but we also always want isadetection.h to be
// included (right after).
Expand Down
20 changes: 10 additions & 10 deletions src/art/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -2284,14 +2284,14 @@ bool art_internal_validate(const art_t *art, const char **reason,
return art_internal_validate_at(art, art->root, validator);
}

_Static_assert(alignof(art_leaf_t) == alignof(art_node4_t),
"Serialization assumes node type alignment is equal");
_Static_assert(alignof(art_leaf_t) == alignof(art_node16_t),
"Serialization assumes node type alignment is equal");
_Static_assert(alignof(art_leaf_t) == alignof(art_node48_t),
"Serialization assumes node type alignment is equal");
_Static_assert(alignof(art_leaf_t) == alignof(art_node256_t),
"Serialization assumes node type alignment is equal");
CROARING_STATIC_ASSERT(alignof(art_leaf_t) == alignof(art_node4_t),
"Serialization assumes node type alignment is equal");
CROARING_STATIC_ASSERT(alignof(art_leaf_t) == alignof(art_node16_t),
"Serialization assumes node type alignment is equal");
CROARING_STATIC_ASSERT(alignof(art_leaf_t) == alignof(art_node48_t),
"Serialization assumes node type alignment is equal");
CROARING_STATIC_ASSERT(alignof(art_leaf_t) == alignof(art_node256_t),
"Serialization assumes node type alignment is equal");

size_t art_size_in_bytes(const art_t *art) {
if (!art_is_shrunken(art)) {
Expand Down Expand Up @@ -2363,8 +2363,8 @@ size_t art_frozen_view(const char *buf, size_t maxbytes, art_t *art) {
if (maxbytes < sizeof(art->capacities)) {
return 0;
}
_Static_assert(sizeof(art->first_free) == sizeof(art->capacities),
"first_free is read from capacities");
CROARING_STATIC_ASSERT(sizeof(art->first_free) == sizeof(art->capacities),
"first_free is read from capacities");
memcpy(art->first_free, buf, sizeof(art->capacities));
memcpy(art->capacities, buf, sizeof(art->capacities));
buf += sizeof(art->capacities);
Expand Down