https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80793
Bug ID: 80793 Summary: three signed conversion warnings for the same expression Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- In a review of an implementation of a new -Wenum-conversion warning (https://gcc.gnu.org/ml/gcc-patches/2017-05/msg00142.html) I brought up a concern over the proliferation of warning options targeting closely related and sometimes even overlapping problems. This is an extreme example of one such problem. The following test case, extracted from the one on line 44 of gcc.dg/Wsign-conversion.c, triggers three distinct yet closely related warnings. Also worth noting are the different ways of what boils down to the same problem (but that's a separate issue, tracked in bug 80731). $ cat t.c && gcc -O2 -S -Wall -Wextra -Wconversion t.c int f (int i) { unsigned char c = i ? (-__SCHAR_MAX__ - 1) : 1U; return c; } t.c: In function ‘f’: t.c:3:46: warning: signed and unsigned type in conditional expression [-Wsign-compare] unsigned char c = i ? (-__SCHAR_MAX__ - 1) : 1U; ^ t.c:3:46: warning: negative integer implicitly converted to unsigned type [-Wsign-conversion] t.c:3:21: warning: conversion to ‘unsigned char’ alters ‘unsigned int’ constant value [-Wconversion] unsigned char c = i ? (-__SCHAR_MAX__ - 1) : 1U; ^ In contrast, Clang issues the following: $ clang -S -Wall -Wextra -Wpedantic -Weverything t.c t.c:3:41: warning: operand of ? changes signedness: 'int' to 'unsigned char' [-Wsign-conversion] unsigned char c = i ? (-__SCHAR_MAX__ - 1) : 1U; ~ ~~~~~~~~~~~~~~~^~~ t.c:1:5: warning: no previous prototype for function 'f' [-Wmissing-prototypes] int f (int i) ^ 2 warnings generated.