* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
@ 2013-02-18 12:08 ` redi at gcc dot gnu.org
2013-02-18 12:53 ` akim.demaille at gmail dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2013-02-18 12:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-02-18 12:07:49 UTC ---
The warning isn't issued when 0 converts to std::nullptr_t, only when it
converts to a pointer type.
struct shared_ptr
{
shared_ptr(decltype(nullptr)) { }
~shared_ptr() { }
};
int main ()
{
shared_ptr a = 0;
shared_ptr b(0);
shared_ptr c{0};
}
(In reply to comment #0)
> It's also a bit sad that only d is diagnosed as useless, although I do
> understand that the shared_ptr has a constructor and a destructor that use
> it.
It's necessary, because otherwise you get bogus warnings from ScopeGuard-style
RAII types.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
2013-02-18 12:08 ` [Bug c++/56373] " redi at gcc dot gnu.org
@ 2013-02-18 12:53 ` akim.demaille at gmail dot com
2013-02-18 13:21 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: akim.demaille at gmail dot com @ 2013-02-18 12:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
--- Comment #2 from Akim Demaille <akim.demaille at gmail dot com> 2013-02-18 12:52:46 UTC ---
Thanks a lot for the detailed answer.
> The warning isn't issued when 0 converts to std::nullptr_t, only when it
> converts to a pointer type.
And shouldn't it?
>> It's also a bit sad that only d is diagnosed as useless, although I do
>> understand that the shared_ptr has a constructor and a destructor that use
>> it.
> It's necessary, because otherwise you get bogus warnings from ScopeGuard-style
> RAII types.
In which case the constructor and destructor would be meaningful,
which is not the case here. But again, thanks for explaining!
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
2013-02-18 12:08 ` [Bug c++/56373] " redi at gcc dot gnu.org
2013-02-18 12:53 ` akim.demaille at gmail dot com
@ 2013-02-18 13:21 ` redi at gcc dot gnu.org
2013-02-18 13:23 ` akim.demaille at gmail dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2013-02-18 13:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-02-18 13:20:41 UTC ---
(In reply to comment #2)
> > It's necessary, because otherwise you get bogus warnings from ScopeGuard-style
> > RAII types.
>
> In which case the constructor and destructor would be meaningful,
> which is not the case here.
~shared_ptr() has non-trivial side-effects, the compiler isn't smart enough to
determine they won't fire when its empty, so it's always meaningful.
If you're smart enough to know the object isn't used then don't create it :)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
` (2 preceding siblings ...)
2013-02-18 13:21 ` redi at gcc dot gnu.org
@ 2013-02-18 13:23 ` akim.demaille at gmail dot com
2013-02-18 16:06 ` paolo.carlini at oracle dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: akim.demaille at gmail dot com @ 2013-02-18 13:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
--- Comment #4 from Akim Demaille <akim.demaille at gmail dot com> 2013-02-18 13:23:08 UTC ---
> If you're smart enough to know the object isn't used then don't create it :)
:) :) :)
> ~shared_ptr() has non-trivial side-effects, the compiler isn't smart enough to
> determine they won't fire when its empty, so it's always meaningful.
I had in mind providing the library authors with an attribute that would
help them influence this diagnostic.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
` (3 preceding siblings ...)
2013-02-18 13:23 ` akim.demaille at gmail dot com
@ 2013-02-18 16:06 ` paolo.carlini at oracle dot com
2013-02-18 16:07 ` paolo.carlini at oracle dot com
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-18 16:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-02-18
AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot
|gnu.org |com
Ever Confirmed|0 |1
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-18 16:05:40 UTC ---
So confirming the first issue. I have a simple patch in testing for it.
About the second issue, it was definitely discussed somewhere else too: there
is always a tension between consistently treating in a similar way elementary
types and classes and avoiding warning for common patterns like RAII.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
` (4 preceding siblings ...)
2013-02-18 16:06 ` paolo.carlini at oracle dot com
@ 2013-02-18 16:07 ` paolo.carlini at oracle dot com
2013-02-20 9:03 ` paolo at gcc dot gnu.org
2013-02-20 9:04 ` paolo.carlini at oracle dot com
7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-18 16:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
` (5 preceding siblings ...)
2013-02-18 16:07 ` paolo.carlini at oracle dot com
@ 2013-02-20 9:03 ` paolo at gcc dot gnu.org
2013-02-20 9:04 ` paolo.carlini at oracle dot com
7 siblings, 0 replies; 9+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-02-20 9:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2013-02-20 09:02:41 UTC ---
Author: paolo
Date: Wed Feb 20 09:02:35 2013
New Revision: 196165
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196165
Log:
/cp
2013-02-20 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/56373
* tree.c (maybe_warn_zero_as_null_pointer_constant): Add.
* cvt.c (ocp_convert): Use the latter.
(cp_convert_to_pointer): Likewise.
* decl.c (check_default_argument): Likewise.
* typeck.c (cp_build_binary_op): Likewise.
* cp-tree.h (maybe_warn_zero_as_null_pointer_constant): Declare.
/testsuite
2013-02-20 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/56373
* g++.dg/cpp0x/Wzero-as-null-pointer-constant-2.C: New.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/cvt.c
trunk/gcc/cp/decl.c
trunk/gcc/cp/tree.c
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/56373] -Wzero-as-null-pointer-constant: does not catch issues with smart pointers
2013-02-18 11:35 [Bug c++/56373] New: -Wzero-as-null-pointer-constant: does not catch issues with smart pointers akim.demaille at gmail dot com
` (6 preceding siblings ...)
2013-02-20 9:03 ` paolo at gcc dot gnu.org
@ 2013-02-20 9:04 ` paolo.carlini at oracle dot com
7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-20 9:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56373
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.8.0
--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-20 09:03:47 UTC ---
Done.
^ permalink raw reply [flat|nested] 9+ messages in thread