public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52806] New: bogus "zero as null pointer constant" warning
@ 2012-03-31 12:35 akim.demaille at gmail dot com
  2012-03-31 13:06 ` [Bug c++/52806] " paolo.carlini at oracle dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: akim.demaille at gmail dot com @ 2012-03-31 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52806
           Summary: bogus "zero as null pointer constant" warning
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: akim.demaille@gmail.com


Well, I suppose that one could argue that this is not a bug,
but then it makes the feature much less useful.

I think that this warning should do nothing when std=c++11 was
not specified and therefore that nullptr is not supported.  Currently
G++ complains about 0 as a pointer even when it does not support
nullptr!

$ cat foo.cc
int *p1 = 0;
int *p2 = nullptr;

$ g++-mp-4.7 -Wzero-as-null-pointer-constant /tmp/foo.cc
/tmp/foo.cc:1:11: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
/tmp/foo.cc:2:11: error: 'nullptr' was not declared in this scope

$ g++-mp-4.7 --version
g++-mp-4.7 (GCC) 4.7.0 20120225 (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] 9+ messages in thread

* [Bug c++/52806] bogus "zero as null pointer constant" warning
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
@ 2012-03-31 13:06 ` paolo.carlini at oracle dot com
  2012-03-31 13:49 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-31 13:06 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-31 12:56:28 UTC ---
Oh well, changing this would be really trivial, but then people would have to
globally switch-on -std=c++11 (which may not be otherwise appropriate) while
working on removing (as much as possible) explicit zeros from C++98-era code. 

But really I don't have a personal strong opinion, and, as I mentioned already,
a patch would be trivial.

Jason, what shall we do?


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

* [Bug c++/52806] bogus "zero as null pointer constant" warning
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
  2012-03-31 13:06 ` [Bug c++/52806] " paolo.carlini at oracle dot com
@ 2012-03-31 13:49 ` paolo.carlini at oracle dot com
  2012-03-31 14:03 ` [Bug c++/52806] "zero as null pointer constant" in C++98 mode paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-31 13:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-31 13:06:14 UTC ---
And, hey, I don't really see what's the problem with not passing the -Wzero* at
all if you don't want the warning.

That can *always* be done, but if I once and for all prevent the -Wzero* from
doing anything useful (or even being rejeted) when the default -std=c++98 is in
effect, then, people who want to use it order to start removing explicit zeros
(like, in conditionals and in many other context where it can easily be done
without involving nullptr) don't have *any* help from the compiler.

All in all, my current opinion is that we don't want to do this.


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

* [Bug c++/52806] "zero as null pointer constant" in C++98 mode
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
  2012-03-31 13:06 ` [Bug c++/52806] " paolo.carlini at oracle dot com
  2012-03-31 13:49 ` paolo.carlini at oracle dot com
@ 2012-03-31 14:03 ` paolo.carlini at oracle dot com
  2012-03-31 14:26 ` akim.demaille at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-03-31 14:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-03-31 13:49:10 UTC ---
Note, even in the *specific* case at issue, maybe the user really wanted p1
statically initialized, or wants an early function call, or something like:

  typedef int* pt;
  int* p1 = pt();

(where pt will be std::nullptr_t in C++11 mode), who knows...


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

* [Bug c++/52806] "zero as null pointer constant" in C++98 mode
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
                   ` (2 preceding siblings ...)
  2012-03-31 14:03 ` [Bug c++/52806] "zero as null pointer constant" in C++98 mode paolo.carlini at oracle dot com
@ 2012-03-31 14:26 ` akim.demaille at gmail dot com
  2012-03-31 14:38 ` akim.demaille at gmail dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: akim.demaille at gmail dot com @ 2012-03-31 14:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Akim Demaille <akim.demaille at gmail dot com> 2012-03-31 14:12:00 UTC ---
(In reply to comment #1)
> Oh well, changing this would be really trivial, but then people would have to
> globally switch-on -std=c++11 (which may not be otherwise appropriate) while
> working on removing (as much as possible) explicit zeros from C++98-era code. 

I don't think this comment makes sense: with what would you want them
to replace these 0, since nullptr is not available?

I'm having precisely this problem in Bison.  I want it to deliver code
which compiles without warning on the user side (so I cannot play
with Autoconf to check for nullptr support), so I use

# ifndef YY_NULL
#  if 201103L <= __cplusplus
#   define YY_NULL nullptr
#  else
#   define YY_NULL 0
#  endif
# endif

Unfortunately the user *will* have warnings if she passes the
warning flag but not -std=c++11.

This is even worse for C++03.

$ g++-mp-4.7 -std=c++03 -Wzero-as-null-pointer-constant /tmp/foo.cc
/tmp/foo.cc:1:11: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
/tmp/foo.cc:2:11: error: 'nullptr' was not declared in this scope

Or, be consistent with the flags that rejected when misused (such as
-Wmissing-prototypes that does not apply to C++) and reject
that warning when not in std=c++11.

The current status introduces non-killable warnings.


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

* [Bug c++/52806] "zero as null pointer constant" in C++98 mode
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
                   ` (3 preceding siblings ...)
  2012-03-31 14:26 ` akim.demaille at gmail dot com
@ 2012-03-31 14:38 ` akim.demaille at gmail dot com
  2012-08-16 10:07 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: akim.demaille at gmail dot com @ 2012-03-31 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Akim Demaille <akim.demaille at gmail dot com> 2012-03-31 14:26:27 UTC ---
(In reply to comment #4)
> I don't think this comment makes sense: with what would you want them
> to replace these 0, since nullptr is not available?

This does not read like I meant, sorry about this.  It should be
"I don't know how to make sense of that comment".


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

* [Bug c++/52806] "zero as null pointer constant" in C++98 mode
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
                   ` (4 preceding siblings ...)
  2012-03-31 14:38 ` akim.demaille at gmail dot com
@ 2012-08-16 10:07 ` paolo.carlini at oracle dot com
  2012-08-16 10:33 ` redi at gcc dot gnu.org
  2012-09-13 11:03 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-08-16 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-08-16 10:07:10 UTC ---
See my Comment #2 and #3: I'm still convinced that the warning can be useful in
C++98 mode too. Unless Jason or another C++ front-end maintainer overrules me,
I'm not going to do anything about this.


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

* [Bug c++/52806] "zero as null pointer constant" in C++98 mode
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
                   ` (5 preceding siblings ...)
  2012-08-16 10:07 ` paolo.carlini at oracle dot com
@ 2012-08-16 10:33 ` redi at gcc dot gnu.org
  2012-09-13 11:03 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2012-08-16 10:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-08-16 10:33:38 UTC ---
(In reply to comment #4)
> Unfortunately the user *will* have warnings if she passes the
> warning flag but not -std=c++11.

So don't use that warning flag. It's not included in -Wall for good reason.


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

* [Bug c++/52806] "zero as null pointer constant" in C++98 mode
  2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
                   ` (6 preceding siblings ...)
  2012-08-16 10:33 ` redi at gcc dot gnu.org
@ 2012-09-13 11:03 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-13 11:03 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-13 11:03:05 UTC ---
Closing.


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

end of thread, other threads:[~2012-09-13 11:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-31 12:35 [Bug c++/52806] New: bogus "zero as null pointer constant" warning akim.demaille at gmail dot com
2012-03-31 13:06 ` [Bug c++/52806] " paolo.carlini at oracle dot com
2012-03-31 13:49 ` paolo.carlini at oracle dot com
2012-03-31 14:03 ` [Bug c++/52806] "zero as null pointer constant" in C++98 mode paolo.carlini at oracle dot com
2012-03-31 14:26 ` akim.demaille at gmail dot com
2012-03-31 14:38 ` akim.demaille at gmail dot com
2012-08-16 10:07 ` paolo.carlini at oracle dot com
2012-08-16 10:33 ` redi at gcc dot gnu.org
2012-09-13 11: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).