Skip to content

Standardize and simplify static_assert usage#444

Merged
qdeslandes merged 2 commits intofacebook:mainfrom
yaakov-stein:standardize_static_assert
Feb 27, 2026
Merged

Standardize and simplify static_assert usage#444
qdeslandes merged 2 commits intofacebook:mainfrom
yaakov-stein:standardize_static_assert

Conversation

@yaakov-stein
Copy link
Contributor

@yaakov-stein yaakov-stein commented Feb 26, 2026

Some cleanup: the docs recommend static_assert() and that is what is used the most throughout the repo. Let's update the style for the few cases that don't use static_assert() currently. We'll also cleanup some static_assert's that didn't have a message and were causing warnings during the build.

Also, we use static_assert_enum_mapping where appropriate and remove instances that were unnecessary.

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Claude: review of facebook/bpfilter #444 (b5a70bb)

Must fix

  • Commit message omits daemon component — The commit message now correctly uses lib,daemon: prefix.

Suggestions

  • Commit message subcomponent helper is misleading — Fixed: subcomponent dropped from the title.
  • Removing bf_static_assert from public headersrc/libbpfilter/include/bpfilter/helper.h — Project is pre-v1 and the macro is a trivial wrapper; acknowledged.
  • Missed static_assert without message in fixup.csrc/bpfilter/cgen/fixup.c:53 — Fixed in current revision: message string added.
  • Use static_assert_enum_mapping macrosrc/libbpfilter/matcher.c, src/bpfilter/cgen/fixup.c — Fixed: commit 2 adopts static_assert_enum_mapping across all applicable sites.
  • static_assert_enum_mapping used for non-enum arrayssrc/libbpfilter/matcher.c:1668, also lines 1710 and 1753 — _bf_ipproto_strs, _bf_icmp_type_strs, and _bf_icmpv6_type_strs are explicitly sized [UINT8_MAX + 1] arrays indexed by raw uint8_t, not enums with a _MAX sentinel. The current revision removes the assertions entirely rather than keeping them as plain static_assert(). While tautological, they document the intent and would become load-bearing if the array declaration changed. Consider restoring as plain static_assert().

Nits

  • Commit body could explain motivation — The commits have no body. The style guide recommends explaining "why" in the description — a brief note about standardizing per the style guide and silencing compiler warnings would help future readers.

@yaakov-stein yaakov-stein force-pushed the standardize_static_assert branch from 3334a66 to b36d3e6 Compare February 26, 2026 20:54
@yaakov-stein yaakov-stein changed the title lib: helper: standardize static_assert usage lib,daemon: standardize static_assert usage Feb 26, 2026
Copy link
Contributor

@qdeslandes qdeslandes left a comment

Choose a reason for hiding this comment

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

Could you also fix the static_assert in matcher.c which do not have any message? It raises a warning during the build.

@yaakov-stein yaakov-stein force-pushed the standardize_static_assert branch from b36d3e6 to 64a2896 Compare February 27, 2026 16:56
@yaakov-stein yaakov-stein force-pushed the standardize_static_assert branch from 64a2896 to ad72e2a Compare February 27, 2026 17:52
@yaakov-stein yaakov-stein changed the title lib,daemon: standardize static_assert usage Standardize and simplify static_assert usage Feb 27, 2026
@yaakov-stein yaakov-stein force-pushed the standardize_static_assert branch from 1000d99 to b5a70bb Compare February 27, 2026 18:28
Copy link
Contributor

@qdeslandes qdeslandes left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@qdeslandes qdeslandes merged commit 3ee0cde into facebook:main Feb 27, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants