[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2015-03-05 Thread paolo.carlini at oracle dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

--- Comment #21 from Paolo Carlini paolo.carlini at oracle dot com ---
*** Bug 65324 has been marked as a duplicate of this bug. ***


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread mw_triad at users dot sourceforge.net

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

--- Comment #12 from Matthew Woehlke mw_triad at users dot sourceforge.net 
2012-11-01 17:47:04 UTC ---
Requires qt-devel installed, but has the benefit of being the exact issue I'm
having in production (on the chance it's something screwy about Qt...):


$ cat zero-as-pointer.cpp 
#include QtGui/QLabel

int main()
{
  QLabel label;
  return 0;
}
$ g++ -std=c++11 -Werror=zero-as-null-pointer-constant zero-as-pointer.cpp 
zero-as-pointer.cpp: In function ‘int main()’:
zero-as-pointer.cpp:5:10: error: zero as null pointer constant
[-Werror=zero-as-null-pointer-constant]
cc1plus: some warnings being treated as errors
Exit 1
$ g++ --version
g++ (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

...maybe it got fixed in 4.7.3?


Note: the problem is this ctor:

explicit QLabel(QWidget *parent=0, Qt::WindowFlags f=0);

If I replace my declaration with:

QLabel label(nullptr, Qt::WindowFlags(nullptr));

...then I get no warning.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread mw_triad at users dot sourceforge.net

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

--- Comment #13 from Matthew Woehlke mw_triad at users dot sourceforge.net 
2012-11-01 17:56:49 UTC ---
...and with your example I do indeed get no warning.

Simplified test case:

$ cat zero-as-pointer.h
#pragma GCC system_header

class Foo
{
public:
  Foo(void** = 0);
};

class Bar
{
public:
  Bar(Foo = 0);
};
$ cat zero-as-pointer.cpp 
#include zero-as-pointer.h

int main()
{
  Bar bar;
  return 0;
}
$ g++ -std=c++11 -Werror=zero-as-null-pointer-constant zero-as-pointer.cpp 
zero-as-pointer.cpp: In function ‘int main()’:
zero-as-pointer.cpp:5:7: error: zero as null pointer constant
[-Werror=zero-as-null-pointer-constant]
cc1plus: some warnings being treated as errors

Apparently it is something about the 'Foo = 0' part (replace Foo with
Qt::WindowFlags in my 'real' example).


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread paolo.carlini at oracle dot com


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



--- Comment #14 from Paolo Carlini paolo.carlini at oracle dot com 2012-11-01 
19:07:10 UTC ---

Ok, I can reproduce this. Note, I don't think it's the same issue reported here

earlier. Apparently something is going wrong with the pragma. A WA is writing:



  Bar(Foo = Foo(0));



in this case the warning is correctly suppressed. The 0 in the Foo constructor

doesn't matter, the warning is correctly suppressed and you can as well remove

it from the testcase. I'm looking into this, hopefully can be fixed without

reworking too many diagnostic things outside this specific warning proper.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread paolo.carlini at oracle dot com


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



--- Comment #15 from Paolo Carlini paolo.carlini at oracle dot com 2012-11-01 
20:52:15 UTC ---

This is what I meant when I said that the issue is different, and is much more

general than -Wzero-as-null-pointer-constant. Consider, eg, with -Woverflow:



#pragma GCC system_header



class Foo

{

 public:

  Foo(signed char);

};



class Bar

{

 public:

  Bar(Foo = 1);

};


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread mwoehlke.floss at gmail dot com


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



--- Comment #16 from mwoehlke.floss at gmail dot com 2012-11-01 22:03:46 UTC ---

On 2012-11-01 16:52, paolo.carlini at oracle dot com wrote:

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

 --- Comment #15 from Paolo Carlini paolo.carlini at oracle dot com 
 2012-11-01 20:52:15 UTC ---



 This is what I meant when I said that the issue is different, and is much more



 general than -Wzero-as-null-pointer-constant. Consider, eg, with -Woverflow:



 #pragma GCC system_header



 class Foo

 {

   public:

Foo(signed char);

 };



 class Bar

 {

   public:

Bar(Foo = 1);

 };



Would you prefer I open a new bug report?


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread paolo.carlini at oracle dot com


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



--- Comment #17 from Paolo Carlini paolo.carlini at oracle dot com 2012-11-01 
22:42:05 UTC ---

If you like, sure. I want to emphasize again that the issue really is about the

behavior of the pragma vs warnings for default arguments, *any* warning, and if

you check is *very* old. Before filing a new PR please double check that the

issue has not been discussed already and maybe resolved as wontfix for some

reason. Thanks.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread manu at gcc dot gnu.org

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

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

   What|Removed |Added

 CC||manu at gcc dot gnu.org

--- Comment #18 from Manuel López-Ibáñez manu at gcc dot gnu.org 2012-11-01 
23:00:51 UTC ---
(In reply to comment #15)
 This is what I meant when I said that the issue is different, and is much more
 general than -Wzero-as-null-pointer-constant. Consider, eg, with -Woverflow:
 
 #pragma GCC system_header
 
 class Foo
 {
  public:
   Foo(signed char);
 };
 
 class Bar
 {
  public:
   Bar(Foo = 1);
 };

The issue is that literals don't have locations, so input_location is used. And
input_location here is in the main file, so system_header doesn't apply. This
is why input_location must die.

Clang uses the correct location for warning, so it honors system_header
(requires -Wsystem-headers):

In file included from pr52718.c:1:
./pr52718.h:11:13: warning: implicit conversion from 'int' to 'signed char'
changes value from 1 to 16 [-Wconstant-conversion]
  Bar(Foo = 1);
^
1 warning generated.

Ultimately, GCC needs to track the locations of literals like clang does.
Everything else is a hack around the main issue. This is PR43486. There have
been some recent attempts
http://gcc.gnu.org/ml/gcc-patches/2012-09/msg01222.html, but I am afraid that
work seems stalled for lack of time/help.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread mw_triad at users dot sourceforge.net


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



--- Comment #19 from Matthew Woehlke mw_triad at users dot sourceforge.net 
2012-11-01 23:04:42 UTC ---

Reported as bug 55173. I'm not going to claim to understand bug 43486

sufficiently to know it is the same issue, but if you are sure, please feel

free to close as duplicate.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-11-01 Thread manu at gcc dot gnu.org

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

--- Comment #20 from Manuel López-Ibáñez manu at gcc dot gnu.org 2012-11-01 
23:23:41 UTC ---
(In reply to comment #19)
 Reported as bug 55173. I'm not going to claim to understand bug 43486
 sufficiently to know it is the same issue, but if you are sure, please feel
 free to close as duplicate.

Well, it is the same underlying issue. It could be worked-around case by case
by passing some location (like the = location) down to the warning point. But
this is likely quite a large refactoring. 

The alternative is some general infrastructure like the one proposed in:
http://gcc.gnu.org/ml/gcc-patches/2012-09/msg01222.html, which would require an
even more massive refactoring to be useful. In fact, that particular proposal
would still require to pass down an explicit location, because it does not
actually add locations to constants, but stores their location together with
the assignment expression (and the assignment expression is not passed down to
the point of warning, only the without-location constant).


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-10-31 Thread mw_triad at users dot sourceforge.net


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



Matthew Woehlke mw_triad at users dot sourceforge.net changed:



   What|Removed |Added



 CC||mw_triad at users dot

   ||sourceforge.net



--- Comment #10 from Matthew Woehlke mw_triad at users dot sourceforge.net 
2012-11-01 00:38:20 UTC ---

This is not fixed (gcc 4.7.2) if the default parameter occurs in a system

header. In such case, I would expect no warning at all. Instead, I get the old

and confusing behavior of gcc warning at the point where the default parameter

is used.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-10-31 Thread paolo.carlini at oracle dot com


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



--- Comment #11 from Paolo Carlini paolo.carlini at oracle dot com 2012-11-01 
01:28:26 UTC ---

I can't reproduce in mainline and 4_7-branch. This is what I tried:



a.h:

#pragma GCC system_header



void* fun(void* a = 0);



a.C:

#include a.h



int main()

{

  fun();

}



if I compile a.C I get no warnings at all (I get warnings with the pragma

commented out, as expected, and in the right place, line #3 of a.h). Likewise,

everything is fine if inside a.h, a boo calls fun(). Do you have a better

testcase?


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2012-03-29
 Ever Confirmed|0   |1

--- Comment #1 from Paolo Carlini paolo.carlini at oracle dot com 2012-03-29 
10:09:51 UTC ---
Confirmed.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

--- Comment #2 from Paolo Carlini paolo.carlini at oracle dot com 2012-03-29 
10:17:49 UTC ---
I guess that first of all we want to fix this to warn at line #1 instead of #2:

void* fun(void* a = 0);
void* f2 = fun();


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #3 from Paolo Carlini paolo.carlini at oracle dot com 2012-03-29 
10:40:41 UTC ---
Considering for simplicity the snippet in Comment #2, I'm not sure whether we
should aim for an unconditional warning for line #1 or a conditional one for
line #2 but referring to line #1. Eg, whether we want to avoid warning for:

void* fun(void* a = 0);
void* f2 = fun(nullptr);

(currently we avoid warning for the latter, which may not be bad, but we fail
completely to refer to line #1)


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread jason at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

--- Comment #4 from Jason Merrill jason at gcc dot gnu.org 2012-03-29 
16:18:34 UTC ---
Since The names in the default argument are bound, and the semantic
constraints are checked, at the point where the default argument appears I
think it makes sense to give this warning at that point as well.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

--- Comment #5 from Paolo Carlini paolo.carlini at oracle dot com 2012-03-29 
17:06:15 UTC ---
I see, thanks. Like we just error out at line #1 for:

void* fun(void* a = 1);
void* f2 = fun(nullptr);


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 AssignedTo|unassigned at gcc dot   |paolo.carlini at oracle dot
   |gnu.org |com

--- Comment #6 from Paolo Carlini paolo.carlini at oracle dot com 2012-03-29 
17:07:49 UTC ---
On it.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

--- Comment #7 from paolo at gcc dot gnu.org paolo at gcc dot gnu.org 
2012-03-29 22:45:56 UTC ---
Author: paolo
Date: Thu Mar 29 22:45:46 2012
New Revision: 185983

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=185983
Log:
/cp
2012-03-29  Paolo Carlini  paolo.carl...@oracle.com

PR c++/52718
* decl.c (check_default_argument): With -Wzero-as-null-pointer-constant
warn for a zero as null pointer constant default argument.

/testsuite
2012-03-29  Paolo Carlini  paolo.carl...@oracle.com

PR c++/52718
* g++.dg/warn/Wzero-as-null-pointer-constant-5.C: New.

Added:
trunk/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/decl.c
trunk/gcc/testsuite/ChangeLog


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo.carlini at oracle dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

Paolo Carlini paolo.carlini at oracle dot com changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution||FIXED
   Target Milestone|--- |4.7.1

--- Comment #9 from Paolo Carlini paolo.carlini at oracle dot com 2012-03-29 
23:21:44 UTC ---
Fixed for 4.7.1 and mainline.


[Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument

2012-03-29 Thread paolo at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52718

--- Comment #8 from paolo at gcc dot gnu.org paolo at gcc dot gnu.org 
2012-03-29 23:21:09 UTC ---
Author: paolo
Date: Thu Mar 29 23:21:02 2012
New Revision: 185984

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=185984
Log:
/cp
2012-03-29  Paolo Carlini  paolo.carl...@oracle.com

PR c++/52718
* decl.c (check_default_argument): With -Wzero-as-null-pointer-constant
warn for a zero as null pointer constant default argument.

/testsuite
2012-03-29  Paolo Carlini  paolo.carl...@oracle.com

PR c++/52718
* g++.dg/warn/Wzero-as-null-pointer-constant-5.C: New.

Added:
   
branches/gcc-4_7-branch/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C
Modified:
branches/gcc-4_7-branch/gcc/cp/ChangeLog
branches/gcc-4_7-branch/gcc/cp/decl.c
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog