public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
@ 2012-03-26  8:18 akim.demaille at gmail dot com
  2012-03-29 10:11 ` [Bug c++/52718] " paolo.carlini at oracle dot com
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: akim.demaille at gmail dot com @ 2012-03-26  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52718
           Summary: -Wzero-as-null-pointer-constant: misleading location
                    for 0 as default argument
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: akim.demaille@gmail.com


Created attachment 26990
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26990
0 instead of nullptr as default argument

I don't think this is a duplicated of 51196.

In the following example, the locations about the uses of 0
instead of nullptr are misleading: none point to the real
issue, but they point to where the default argument was used.

$ g++-mp-4.8 -Wzero-as-null-pointer-constant -c /tmp/foo.cc
/tmp/foo.cc: In constructor 'bar::bar()':
/tmp/foo.cc:10:9: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
/tmp/foo.cc: At global scope:
/tmp/foo.cc:15:27: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
/tmp/foo.cc:16:22: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]

$ g++-mp-4.8 --version
g++-mp-4.8 (GCC) 4.8.0 20120318 (experimental)
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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
@ 2012-03-29 10:11 ` paolo.carlini at oracle dot com
  2012-03-29 10:25 ` paolo.carlini at oracle dot com
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 10:11 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
  2012-03-29 10:11 ` [Bug c++/52718] " paolo.carlini at oracle dot com
@ 2012-03-29 10:25 ` paolo.carlini at oracle dot com
  2012-03-29 10:43 ` paolo.carlini at oracle dot com
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 10:25 UTC (permalink / raw)
  To: gcc-bugs

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();


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
  2012-03-29 10:11 ` [Bug c++/52718] " paolo.carlini at oracle dot com
  2012-03-29 10:25 ` paolo.carlini at oracle dot com
@ 2012-03-29 10:43 ` paolo.carlini at oracle dot com
  2012-03-29 16:32 ` jason at gcc dot gnu.org
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 10:43 UTC (permalink / raw)
  To: gcc-bugs

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)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (2 preceding siblings ...)
  2012-03-29 10:43 ` paolo.carlini at oracle dot com
@ 2012-03-29 16:32 ` jason at gcc dot gnu.org
  2012-03-29 17:08 ` paolo.carlini at oracle dot com
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: jason at gcc dot gnu.org @ 2012-03-29 16:32 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (3 preceding siblings ...)
  2012-03-29 16:32 ` jason at gcc dot gnu.org
@ 2012-03-29 17:08 ` paolo.carlini at oracle dot com
  2012-03-29 17:39 ` paolo.carlini at oracle dot com
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 17:08 UTC (permalink / raw)
  To: gcc-bugs

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);


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (4 preceding siblings ...)
  2012-03-29 17:08 ` paolo.carlini at oracle dot com
@ 2012-03-29 17:39 ` paolo.carlini at oracle dot com
  2012-03-29 23:22 ` paolo.carlini at oracle dot com
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 17:39 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (5 preceding siblings ...)
  2012-03-29 17:39 ` paolo.carlini at oracle dot com
@ 2012-03-29 23:22 ` paolo.carlini at oracle dot com
  2012-03-29 23:22 ` paolo at gcc dot gnu.org
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-29 23:22 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (6 preceding siblings ...)
  2012-03-29 23:22 ` paolo.carlini at oracle dot com
@ 2012-03-29 23:22 ` paolo at gcc dot gnu.org
  2012-03-30  0:29 ` paolo at gcc dot gnu.org
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-03-29 23:22 UTC (permalink / raw)
  To: gcc-bugs

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=gcc&view=rev&rev=185983
Log:
/cp
2012-03-29  Paolo Carlini  <paolo.carlini@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.carlini@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


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (7 preceding siblings ...)
  2012-03-29 23:22 ` paolo at gcc dot gnu.org
@ 2012-03-30  0:29 ` paolo at gcc dot gnu.org
  2012-11-01  0:38 ` mw_triad at users dot sourceforge.net
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-03-30  0:29 UTC (permalink / raw)
  To: gcc-bugs

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=gcc&view=rev&rev=185984
Log:
/cp
2012-03-29  Paolo Carlini  <paolo.carlini@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.carlini@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


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (8 preceding siblings ...)
  2012-03-30  0:29 ` paolo at gcc dot gnu.org
@ 2012-11-01  0:38 ` mw_triad at users dot sourceforge.net
  2012-11-01  1:28 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: mw_triad at users dot sourceforge.net @ 2012-11-01  0:38 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (9 preceding siblings ...)
  2012-11-01  0:38 ` mw_triad at users dot sourceforge.net
@ 2012-11-01  1:28 ` paolo.carlini at oracle dot com
  2012-11-01 17:47 ` mw_triad at users dot sourceforge.net
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-01  1:28 UTC (permalink / raw)
  To: gcc-bugs


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?


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (10 preceding siblings ...)
  2012-11-01  1:28 ` paolo.carlini at oracle dot com
@ 2012-11-01 17:47 ` mw_triad at users dot sourceforge.net
  2012-11-01 17:57 ` mw_triad at users dot sourceforge.net
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: mw_triad at users dot sourceforge.net @ 2012-11-01 17:47 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (11 preceding siblings ...)
  2012-11-01 17:47 ` mw_triad at users dot sourceforge.net
@ 2012-11-01 17:57 ` mw_triad at users dot sourceforge.net
  2012-11-01 19:07 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: mw_triad at users dot sourceforge.net @ 2012-11-01 17:57 UTC (permalink / raw)
  To: gcc-bugs


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).


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (12 preceding siblings ...)
  2012-11-01 17:57 ` mw_triad at users dot sourceforge.net
@ 2012-11-01 19:07 ` paolo.carlini at oracle dot com
  2012-11-01 20:52 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-01 19:07 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (13 preceding siblings ...)
  2012-11-01 19:07 ` paolo.carlini at oracle dot com
@ 2012-11-01 20:52 ` paolo.carlini at oracle dot com
  2012-11-01 22:04 ` mwoehlke.floss at gmail dot com
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-01 20:52 UTC (permalink / raw)
  To: gcc-bugs


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 = 10000);
};


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (14 preceding siblings ...)
  2012-11-01 20:52 ` paolo.carlini at oracle dot com
@ 2012-11-01 22:04 ` mwoehlke.floss at gmail dot com
  2012-11-01 22:42 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: mwoehlke.floss at gmail dot com @ 2012-11-01 22:04 UTC (permalink / raw)
  To: gcc-bugs


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 = 10000);
> };

Would you prefer I open a new bug report?


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (15 preceding siblings ...)
  2012-11-01 22:04 ` mwoehlke.floss at gmail dot com
@ 2012-11-01 22:42 ` paolo.carlini at oracle dot com
  2012-11-01 23:01 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-01 22:42 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (16 preceding siblings ...)
  2012-11-01 22:42 ` paolo.carlini at oracle dot com
@ 2012-11-01 23:01 ` manu at gcc dot gnu.org
  2012-11-01 23:05 ` mw_triad at users dot sourceforge.net
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: manu at gcc dot gnu.org @ 2012-11-01 23:01 UTC (permalink / raw)
  To: gcc-bugs


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 = 10000);
> };

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 10000 to 16 [-Wconstant-conversion]
  Bar(Foo = 10000);
            ^~~~~
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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (17 preceding siblings ...)
  2012-11-01 23:01 ` manu at gcc dot gnu.org
@ 2012-11-01 23:05 ` mw_triad at users dot sourceforge.net
  2012-11-01 23:24 ` manu at gcc dot gnu.org
  2015-03-05 21:03 ` paolo.carlini at oracle dot com
  20 siblings, 0 replies; 22+ messages in thread
From: mw_triad at users dot sourceforge.net @ 2012-11-01 23:05 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (18 preceding siblings ...)
  2012-11-01 23:05 ` mw_triad at users dot sourceforge.net
@ 2012-11-01 23:24 ` manu at gcc dot gnu.org
  2015-03-05 21:03 ` paolo.carlini at oracle dot com
  20 siblings, 0 replies; 22+ messages in thread
From: manu at gcc dot gnu.org @ 2012-11-01 23:24 UTC (permalink / raw)
  To: gcc-bugs


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).


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Bug c++/52718] -Wzero-as-null-pointer-constant: misleading location for 0 as default argument
  2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
                   ` (19 preceding siblings ...)
  2012-11-01 23:24 ` manu at gcc dot gnu.org
@ 2015-03-05 21:03 ` paolo.carlini at oracle dot com
  20 siblings, 0 replies; 22+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-05 21:03 UTC (permalink / raw)
  To: gcc-bugs

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. ***


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2015-03-05 21:03 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26  8:18 [Bug c++/52718] New: -Wzero-as-null-pointer-constant: misleading location for 0 as default argument akim.demaille at gmail dot com
2012-03-29 10:11 ` [Bug c++/52718] " paolo.carlini at oracle dot com
2012-03-29 10:25 ` paolo.carlini at oracle dot com
2012-03-29 10:43 ` paolo.carlini at oracle dot com
2012-03-29 16:32 ` jason at gcc dot gnu.org
2012-03-29 17:08 ` paolo.carlini at oracle dot com
2012-03-29 17:39 ` paolo.carlini at oracle dot com
2012-03-29 23:22 ` paolo.carlini at oracle dot com
2012-03-29 23:22 ` paolo at gcc dot gnu.org
2012-03-30  0:29 ` paolo at gcc dot gnu.org
2012-11-01  0:38 ` mw_triad at users dot sourceforge.net
2012-11-01  1:28 ` paolo.carlini at oracle dot com
2012-11-01 17:47 ` mw_triad at users dot sourceforge.net
2012-11-01 17:57 ` mw_triad at users dot sourceforge.net
2012-11-01 19:07 ` paolo.carlini at oracle dot com
2012-11-01 20:52 ` paolo.carlini at oracle dot com
2012-11-01 22:04 ` mwoehlke.floss at gmail dot com
2012-11-01 22:42 ` paolo.carlini at oracle dot com
2012-11-01 23:01 ` manu at gcc dot gnu.org
2012-11-01 23:05 ` mw_triad at users dot sourceforge.net
2012-11-01 23:24 ` manu at gcc dot gnu.org
2015-03-05 21:03 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).