This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR 35635 -Wconversion problematic with bitfields


The following patch fixes PR 35635 by doing two things:

1) Boolean expressions are ignored. I cannot think of a testcase where
an implicit conversion from boolean to another type loses information.
Since C front-end uses integer_type for boolean expressions, not
ignoring boolean expressions led to unwanted warnings.

2) The type of a conditional expression is ignored if both branches of
the expression are constants. In such case, we look directly at the
conversion performed on each branch. This change makes -Wconversion to
give finer warnings in some cases:

uc = x ? 1 : -1;

instead of : warning: conversion to 'unsigned char' from 'int' [-Wconversion]
it now says: warning: negative integer implicitly converted to
unsigned type [-Wsign-conversion]

Therefore, I had to update a bunch of testcases.

Bootstrapped and regression tested on x86_64-pc-linux-gnu with
--enable-languages=all.

OK for trunk?

2008-08-01  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

  PR 35635
  * c-common.c (conversion_warning): Use a switch. Ignore boolean
expressions. Handle COND_EXPR with constant operands.

testsuite/
  * gcc.dg/pr35635.C: New.
  * gcc.dg/Wconversion-integer.c: Update.
  * gcc.dg/Wconversion-integer-no-sign.c: Update.
  * gcc.dg/Wsign-conversion.c: Update.
  * g++.dg/warn/Wconversion-integer.C: Update.
  * g++.dg/warn/Wsign-conversion.C: Update.

Attachment: fix-pr35635.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]