[Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767 jh718.park at samsung dot com changed: What|Removed |Added Status|WAITING |RESOLVED Resolution|--- |INVALID --- Comment #4 from jh718.park at samsung dot com --- (In reply to Jonathan Wakely from comment #3) > (In reply to jh718.park from comment #0) > > For these variables below, > > > > unsigned m_schemeEnd : 26; > > unsigned m_userStart; > > > > m_userStart == m_schemeEnd + 1 > > > > this comparison emits a compiler warning as below. > > > > warning: comparison of integer expressions of different signedness: > > ‘unsigned int’ and ‘int’ [-Wsign-compare] > > Why do you think that's wrong? > > In [conv.prom] p5 the standard says: > > "A prvalue for an integral bit-field (11.4.9) can be converted to a prvalue > of type int if int can represent all the values of the bit-field;" > > Since int is wider than 26 bits it can represent all the values of > m_schemeEnd, so the operands of 'm_schemeEnd + 1' are both promoted to int, > and the result is an int. Thank you for your comment, Jonathan. I understand your point. I thought that unsigned bitfield should be converted to unsigned during usual arithmetic conversions without knowing the item, http://eel.is/c++draft/conv.prom#5. Then, I will mark this issue as resolved/invalid, and update the bug https://bugs.webkit.org/show_bug.cgi?id=211044 with the comment you left here. Thank you for your help:)
[Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767 --- Comment #3 from Jonathan Wakely --- (In reply to jh718.park from comment #0) > For these variables below, > > unsigned m_schemeEnd : 26; > unsigned m_userStart; > > m_userStart == m_schemeEnd + 1 > > this comparison emits a compiler warning as below. > > warning: comparison of integer expressions of different signedness: > ‘unsigned int’ and ‘int’ [-Wsign-compare] Why do you think that's wrong? In [conv.prom] p5 the standard says: "A prvalue for an integral bit-field (11.4.9) can be converted to a prvalue of type int if int can represent all the values of the bit-field;" Since int is wider than 26 bits it can represent all the values of m_schemeEnd, so the operands of 'm_schemeEnd + 1' are both promoted to int, and the result is an int.
[Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767 Richard Biener changed: What|Removed |Added Keywords||diagnostic, wrong-code Ever confirmed|0 |1 Status|UNCONFIRMED |WAITING Last reconfirmed||2020-04-27 --- Comment #2 from Richard Biener --- Who knows, please provide a testcase that reproduces the issue.
[Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767 --- Comment #1 from Andrew Pinski --- I think this has been fixed on the trunk.