Zend: Add unsigned suffix for bitmask flags#14449
Conversation
Bitshifts are only well defined for unsigned integers
4e9166f to
7adb5c1
Compare
|
What does this fix? void test() {
unsigned x = 1 << 5;
} |
|
The issue is if you enable the because the signed bitmask flag is being assigned to an unsigned struct field. And because virtually all fields in Zend that are bitmask flags are of type I'll fix the description of the PR as it is indeed the wrong compiler flag I mentioned. |
You are right. May be changing the left operand of the shift is enough? void test(unsigned *p) {
*p &= ~(1U << 5);
}It looks like Rust changes the mind of C compilers developers and we have to bloat the source code with more and more qualifications... :) |
Bit shifts are only well-defined for unsigned integers:
Section
6.5.7 Bitwise shift operatorsof the latest C23 draft (and this is also valid in C99): https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdfMoreover, a lot of the results of these flags are stored in
uint32_tfields.This is part of being able to enable the
-Wconversionwarning.