Skip to content

[th/static-assert-via-bitfield] std-aux: implement static-asserts via bitfields

Thomas Haller requested to merge th/static-assert-via-bitfield into main

The implementation for static asserts with (sizeof(char[(cond) ? 1 : -1])) silently fails if the condition is not a compile time constant, because it results in a VLA which is evaluated at runtime. Well, for that reason we build with -Wvla to catch accidentally using a non-const expression in a static assert. But still, we can do better. Use instead bitfields to trigger the compiler error. This works only with static expressions and also without -Wvla.

Edited by Thomas Haller

Merge request reports