public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94767] New: (unsigned bitfield) + (int) operation results in int, not unsigned int.
@ 2020-04-26 2:08 jh718.park at samsung dot com
2020-04-26 8:41 ` [Bug c++/94767] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: jh718.park at samsung dot com @ 2020-04-26 2:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767
Bug ID: 94767
Summary: (unsigned bitfield) + (int) operation results in int,
not unsigned int.
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jh718.park at samsung dot com
Target Milestone: ---
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]
This bug was found during WebKit gtk port build with gcc 9.3.0.
Temporarily, this warning was removed by this patch,
https://trac.webkit.org/changeset/260715/webkit
like
bool slashSlashNeeded = m_userStart == static_cast<unsigned>(m_schemeEnd + 1);
but we think that this bug should be fixed in gcc.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
2020-04-26 2:08 [Bug c++/94767] New: (unsigned bitfield) + (int) operation results in int, not unsigned int jh718.park at samsung dot com
@ 2020-04-26 8:41 ` pinskia at gcc dot gnu.org
2020-04-27 6:40 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-26 8:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this has been fixed on the trunk.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
2020-04-26 2:08 [Bug c++/94767] New: (unsigned bitfield) + (int) operation results in int, not unsigned int jh718.park at samsung dot com
2020-04-26 8:41 ` [Bug c++/94767] " pinskia at gcc dot gnu.org
@ 2020-04-27 6:40 ` rguenth at gcc dot gnu.org
2020-04-27 8:36 ` redi at gcc dot gnu.org
2020-04-27 10:03 ` jh718.park at samsung dot com
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-27 6:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767
Richard Biener <rguenth at gcc dot gnu.org> 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 <rguenth at gcc dot gnu.org> ---
Who knows, please provide a testcase that reproduces the issue.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
2020-04-26 2:08 [Bug c++/94767] New: (unsigned bitfield) + (int) operation results in int, not unsigned int jh718.park at samsung dot com
2020-04-26 8:41 ` [Bug c++/94767] " pinskia at gcc dot gnu.org
2020-04-27 6:40 ` rguenth at gcc dot gnu.org
@ 2020-04-27 8:36 ` redi at gcc dot gnu.org
2020-04-27 10:03 ` jh718.park at samsung dot com
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-27 8:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/94767] (unsigned bitfield) + (int) operation results in int, not unsigned int.
2020-04-26 2:08 [Bug c++/94767] New: (unsigned bitfield) + (int) operation results in int, not unsigned int jh718.park at samsung dot com
` (2 preceding siblings ...)
2020-04-27 8:36 ` redi at gcc dot gnu.org
@ 2020-04-27 10:03 ` jh718.park at samsung dot com
3 siblings, 0 replies; 5+ messages in thread
From: jh718.park at samsung dot com @ 2020-04-27 10:03 UTC (permalink / raw)
To: gcc-bugs
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:)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-04-27 10:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26 2:08 [Bug c++/94767] New: (unsigned bitfield) + (int) operation results in int, not unsigned int jh718.park at samsung dot com
2020-04-26 8:41 ` [Bug c++/94767] " pinskia at gcc dot gnu.org
2020-04-27 6:40 ` rguenth at gcc dot gnu.org
2020-04-27 8:36 ` redi at gcc dot gnu.org
2020-04-27 10:03 ` jh718.park at samsung dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).