Bug 107314 - [13 Regression] New -Wsign-compare since r13-3360-g3b3083a598ca3f4b
Summary: [13 Regression] New -Wsign-compare since r13-3360-g3b3083a598ca3f4b
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: 13.0
Assignee: Not yet assigned to anyone
Keywords: diagnostic
Depends on:
Reported: 2022-10-19 07:11 UTC by Martin Liška
Modified: 2023-11-10 03:07 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2022-10-19 07:11:02 UTC
Reduced from grub package:

$ cat http.i
int port;

enum {
  HTTP_MAX_CHUNK_SIZE = 0x80000000
http_establish_file() {
  return 0 ? port : HTTP_PORT;

$ gcc http.i -c -Werror=sign-compare -O2
http.i: In function ‘http_establish_file’:
http.i:8:14: error: operand of ‘?:’ changes signedness from ‘int’ to ‘enum <anonymous>’ due to unsignedness of other operand [-Werror=sign-compare]
    8 |   return 0 ? port : HTTP_PORT;
      |              ^~~~
cc1: some warnings being treated as errors
Comment 1 jsm-csl@polyomino.org.uk 2022-10-19 16:58:12 UTC
This is a deliberate change: if any enumerators are outside the range of 
int, then all enumerators now have the enum type, rather than those 
outside the range of int having the enum type and those inside the range 
of int having type int.  (The logic to determine the integer type with 
which the enum type is compatible is unchanged.  In the case of this 
testcase, it produces unsigned int.)

While, as noted in the commit message, the change could be made 
conditional on C2x mode if necessary, I'm doubtful if that would actually 
help grub; presumably they'd rather change things so they work in C2x mode 
rather than keeping using an older mode after -std=gnu2x is the default, 
or postponing the fix until then.
Comment 2 Martin Liška 2022-10-20 15:48:02 UTC
All right, I've just created upstream issue:
Comment 3 Andrew Pinski 2022-10-20 15:52:19 UTC
(In reply to Martin Liška from comment #2)
> All right, I've just created upstream issue:
> https://savannah.gnu.org/bugs/index.php?63246

Note I submitted a bug about not being able to put this URL in the see also field (PR 107333).
Comment 4 Joseph S. Myers 2022-10-20 17:05:53 UTC
Closing this bug, since the new behavior is as intended.