mac: fix -Wgnu-folding-constant build error on newer Apple clang #816
No reviewers
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi!816
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-mac-clang-folding-constant"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
create_device_info_with_usage()inmac/hid.cdeclared the local buffer length as aconst int:In C a
const-qualified variable is not a constant expression, sobufis 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:Use an
enumconstant instead — a proper integer constant expression — sobufis an ordinary fixed-size array on every compiler. It is namedBufLen(notBUF_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
Great. Everything is fine now.