mac: fix -Wgnu-folding-constant build error on newer Apple clang #816

Merged
Youw merged 1 commit from fix-mac-clang-folding-constant into master 2026-06-08 18:49:29 -05:00
Youw commented 2026-06-08 08:15:53 -05:00 (Migrated from github.com)

Summary

create_device_info_with_usage() in mac/hid.c declared the local buffer length as a const int:

const int BUF_LEN = 256;
wchar_t buf[BUF_LEN];

In C a const-qualified variable is not a constant expression, so buf is technically a VLA that the compiler folds to a fixed-size array. Newer Apple clang (clang 21, shipped with macOS 26) reports the fold under -Wgnu-folding-constant; since the project builds with -pedantic -Werror, it becomes a hard error:

mac/hid.c:548:14: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant]

Use an enum constant instead — a proper integer constant expression — so buf is an ordinary fixed-size array on every compiler. It is named BufLen (not BUF_LEN) so an all-caps identifier can't collide with a macro of the same name. No behavior change.

The CI macOS runner's clang doesn't flag this yet, so it builds green there, but it breaks local builds on up-to-date Macs. Reported by @mcuee while testing the virtual-device tests (#815) on macOS 26.5.1 / Apple clang 21.

Refs: #815

Assisted-by: claude-code:claude-opus-4-8

## Summary `create_device_info_with_usage()` in `mac/hid.c` declared the local buffer length as a `const int`: ```c const int BUF_LEN = 256; wchar_t buf[BUF_LEN]; ``` In C a `const`-qualified variable is not a constant expression, so `buf` is technically a VLA that the compiler folds to a fixed-size array. Newer Apple clang (clang 21, shipped with macOS 26) reports the fold under `-Wgnu-folding-constant`; since the project builds with `-pedantic -Werror`, it becomes a hard error: ``` mac/hid.c:548:14: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant] ``` Use an `enum` constant instead — a proper integer constant expression — so `buf` is an ordinary fixed-size array on every compiler. It is named `BufLen` (not `BUF_LEN`) so an all-caps identifier can't collide with a macro of the same name. No behavior change. The CI macOS runner's clang doesn't flag this yet, so it builds green there, but it breaks local builds on up-to-date Macs. Reported by @mcuee while testing the virtual-device tests (#815) on macOS 26.5.1 / Apple clang 21. Refs: #815 Assisted-by: claude-code:claude-opus-4-8
mcuee commented 2026-06-08 18:48:45 -05:00 (Migrated from github.com)

Great. Everything is fine now.

Great. Everything is fine now.
mcuee (Migrated from github.com) approved these changes 2026-06-08 18:49:00 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi!816
No description provided.