PR 35635 -Wconversion problematic with bitfields

Manuel López-Ibáñez lopezibanez@gmail.com
Fri Aug 1 14:38:00 GMT 2008


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.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fix-pr35635.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080801/9df4280a/attachment.ksh>


More information about the Gcc-patches mailing list