This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
coercion warnings for NULL in C front end
- From: "Manuel LÃpez-IbÃÃez" <lopezibanez at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 6 Jul 2006 22:54:28 +0100
- Subject: coercion warnings for NULL in C front end
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
}