coercion warnings for NULL in C front end

Manuel López-Ibáñez lopezibanez@gmail.com
Thu Jul 6 21:54:00 GMT 2006


Dear all,

Once the implementation of warnings for coercions that may change a
value in the simplest cases is roughly completed [1], I am starting to
consider other possible cases. As an example, the C++ front end given
the Wconversion option currently emits a warning for:

int i = NULL;

Would it be appropriate for the C front end to copy C++ handling of
NULL with regards to -Wconversion ? A more complete testcase can be
found at the end of the message and in the Wcoercion page [2].

Cheers,

Manuel.

[1] http://gcc.gnu.org/ml/gcc-patches/2006-07/msg00098.html
[2] http://gcc.gnu.org/wiki/Wcoercion#NULL


void k(int) {}

int main()
{
  int i = NULL; // { dg-warning "" } converting NULL to non-pointer type
  float z = NULL; // { dg-warning "" } converting NULL to non-pointer type
  int a[2];

  i != NULL; // { dg-warning "" } NULL used in arithmetic
  NULL != z; // { dg-warning "" } NULL used in arithmetic
  k != NULL; // No warning: decay conversion
  NULL != a; // Likewise.
  -NULL;     // { dg-warning "" } converting NULL to non-pointer type
  +NULL;     // { dg-warning "" } converting NULL to non-pointer type
  ~NULL;     // { dg-warning "" } converting NULL to non-pointer type
  a[NULL] = 3; // { dg-warning "" } converting NULL to non-pointer-type
  i = NULL;  // { dg-warning "" } converting NULL to non-pointer type
  z = NULL;  // { dg-warning "" } converting NULL to non-pointer type
  k(NULL);   // { dg-warning "" } converting NULL to int
  NULL && NULL; // No warning: converting NULL to bool is OK
}



More information about the Gcc mailing list