[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2014-06-30 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 CC||mpolacek at gcc dot gnu.org
 Resolution|--- |FIXED

--- Comment #13 from Marek Polacek mpolacek at gcc dot gnu.org ---
So fixed.


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-04-01 Thread jsm28 at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #12 from Joseph S. Myers jsm28 at gcc dot gnu.org 2011-04-01 
19:36:27 UTC ---
Author: jsm28
Date: Fri Apr  1 19:36:23 2011
New Revision: 171850

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=171850
Log:
2011-04-01  Vincent Lefevre  vincent+...@vinc17.org

PR c/36299
* gcc.dg/Waddress.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/Waddress.c
Modified:
trunk/gcc/testsuite/ChangeLog


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-11 Thread vincent-gcc at vinc17 dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #11 from Vincent Lefèvre vincent-gcc at vinc17 dot net 2011-03-11 
15:15:16 UTC ---
(In reply to comment #10)
 If you don't want this warning, please contribute a testcase to
 gcc-patc...@gcc.gnu.org, so this warning won't reappear in the future:

Done: http://gcc.gnu.org/ml/gcc-patches/2011-03/msg00624.html


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-02 Thread manu at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #8 from Manuel López-Ibáñez manu at gcc dot gnu.org 2011-03-02 
10:51:51 UTC ---
(In reply to comment #7)
 (In reply to comment #6)
  I think the intention is to warn, at least for a == (void *)0, since the
  address of a cannot be zero or null. So I would say that this is a 
  regression.
 
 But this is valid in C, and in practice, such a test can occur in macro
 expansions: a macro can check whether some pointer is null before doing
 something with it. There shouldn't be a warning in such a case.

Every warning warns about something valid in C, otherwise it would be an error
not a warning.


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-02 Thread vincent at vinc17 dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #9 from Vincent Lefèvre vincent at vinc17 dot org 2011-03-02 
15:17:33 UTC ---
(In reply to comment #8)
 Every warning warns about something valid in C, otherwise it would be an error
 not a warning.

No, for instance:

int main(void)
{
  int i;
  return i;
}

This is undefined behavior and detected by GCC, but one gets only a warning:

tst.c: In function ‘main’:
tst.c:4: warning: ‘i’ is used uninitialized in this function

Compare to a == 0 in the above testcase, which has a well-defined behavior.


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-02 Thread manu at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

Manuel López-Ibáñez manu at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2011.03.02 17:06:47
 Ever Confirmed|0   |1

--- Comment #10 from Manuel López-Ibáñez manu at gcc dot gnu.org 2011-03-02 
17:06:47 UTC ---
(In reply to comment #9)
 This is undefined behavior and detected by GCC, but one gets only a warning:

I am not going to waste time discussing the fine-points of what is a valid C
program. If you don't want this warning, please contribute a testcase to
gcc-patc...@gcc.gnu.org, so this warning won't reappear in the future:

http://gcc.gnu.org/wiki/HowToPrepareATestcase

Otherwise, someone will come who thinks that this should be warned and they
will fix it.


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-01 Thread manu at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #4 from Manuel López-Ibáñez manu at gcc dot gnu.org 2011-03-01 
09:14:27 UTC ---
(In reply to comment #3)
 
 The documentation should be improved anyway (the word suspicious is very
 subjective).
 

Please propose a patch.

  You should be able to work-around the macro case by casting the array to 
  (char
  *) or perhaps casting to (void *) ?
 
 Yes, this makes sense. Perhaps this should be documented.

Is it working? I meant to say ideally one should be able to do this but I
don't think it is working right now (and probably there are not testcases
testing this).

 
 How about something like __extension__, e.g. __no_warnings__ would disable the
 warnings for the following statement or expression? If expression, one could

There was a patch floating around in gcc-patches to implement that but since
GCC location info is far from perfect (especially on macro expansions), I think
it won't work well in practice. Moreover, the preferred way is to use the
existing diagnostic pragmas.
http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-01 Thread vincent at vinc17 dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #5 from Vincent Lefèvre vincent at vinc17 dot org 2011-03-01 
15:05:19 UTC ---
Under Debian, I can no longer reproduce the problem with GCC 4.5.2:

$ gcc-4.5 -Wall warn-nulladdress.c
$ gcc-4.5 -Waddress warn-nulladdress.c
$ gcc-4.4 -Wall warn-nulladdress.c
warn-nulladdress.c: In function ‘main’:
warn-nulladdress.c:14: warning: the address of ‘a’ will never be NULL
$ gcc-4.4 -Waddress warn-nulladdress.c
warn-nulladdress.c: In function ‘main’:
warn-nulladdress.c:14: warning: the address of ‘a’ will never be NULL

So, I assume that it has been fixed anyway. Do you confirm?


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-01 Thread manu at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #6 from Manuel López-Ibáñez manu at gcc dot gnu.org 2011-03-01 
15:37:25 UTC ---
(In reply to comment #5)
 
 So, I assume that it has been fixed anyway. Do you confirm?

I think the intention is to warn, at least for a == (void *)0, since the
address of a cannot be zero or null. So I would say that this is a regression.


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2011-03-01 Thread vincent at vinc17 dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299

--- Comment #7 from Vincent Lefèvre vincent at vinc17 dot org 2011-03-02 
01:15:23 UTC ---
(In reply to comment #6)
 I think the intention is to warn, at least for a == (void *)0, since the
 address of a cannot be zero or null. So I would say that this is a regression.

But this is valid in C, and in practice, such a test can occur in macro
expansions: a macro can check whether some pointer is null before doing
something with it. There shouldn't be a warning in such a case.


[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2008-08-23 Thread manu at gcc dot gnu dot org


--- Comment #2 from manu at gcc dot gnu dot org  2008-08-23 12:53 ---
Andrew, how could we detect that it is a decayed array?

I think we would like to warn for 

if (a == (void *) 0) 

but not for

if ((void *)a == 0) 

or even if possible not for 

if (a[0] == 0) 

Vincent, 
this warning was added on purpose, because probably someone requested it. I
don't see that it is very different from the documented case of using the
address of a function in a conditional.

You should be able to work-around the macro case by casting the array to (char
*) or perhaps casting to (void *) ? That said, we would like to not warn within
macros for a wide range of warnings but we don't have the infrastructure to do
that yet.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299



[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2008-08-23 Thread vincent at vinc17 dot org


--- Comment #3 from vincent at vinc17 dot org  2008-08-23 20:00 ---
(In reply to comment #2)
 this warning was added on purpose, because probably someone requested it. I
 don't see that it is very different from the documented case of using the
 address of a function in a conditional.

The documentation should be improved anyway (the word suspicious is very
subjective).

 You should be able to work-around the macro case by casting the array to (char
 *) or perhaps casting to (void *) ?

Yes, this makes sense. Perhaps this should be documented.

 That said, we would like to not warn within
 macros for a wide range of warnings but we don't have the infrastructure to do
 that yet.

How about something like __extension__, e.g. __no_warnings__ would disable the
warnings for the following statement or expression? If expression, one could
still use __no_warnings__ with ({ ... }). Keywords for individual warnings or
warning groups would even be better. At the same time, it would be nice to have
some macro defined, declaring that such a keyword is available (that would be
much better than testing the GCC version).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299



[Bug c/36299] spurious and undocumented warning with -Waddress for a == 0 when a is an array

2008-05-22 Thread pinskia at gcc dot gnu dot org


--- Comment #1 from pinskia at gcc dot gnu dot org  2008-05-22 20:00 ---

  if (a == 0)
return 1;
  else if (a == (void *) 0)

Those two should warn about being address being zero.  a decays to a pointer
type and really a[0].

-- Pinski


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36299