public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35878] Useless NULL pointer check when constructing object
       [not found] <bug-35878-4@http.gcc.gnu.org/bugzilla/>
@ 2013-09-11 12:59 ` glisse at gcc dot gnu.org
  2013-09-11 13:39 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-09-11 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
                 CC|                            |glisse at gcc dot gnu.org,
                   |                            |redi at gcc dot gnu.org
         Resolution|DUPLICATE                   |---

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
I am separating this PR from PR 19476 because it really isn't the same at all.

Copying Ian's later comment so it isn't lost: "Note that bug 35878, which was
closed as a duplicate of this one, was a case of placement new.  For placement
new the check for a NULL pointer is particularly useless, as the language
standard says that placement new is required to return the pointer which was
passed in."

The check for a null pointer after a call to placement new is sadly required by
the standard (if anyone cares to try and get that changed, please go ahead).
See this link for instance for an analysis:

http://stackoverflow.com/questions/17571103/passing-null-pointer-to-placement-new

p=new(nullptr)int(42); is an absurd but valid way of saying p=0;.


For the compiler to know that the pointer is non-zero, it would need to see
where the pointer is coming from, which is not the case in this testcase.

The only place I can think of where we could tell the compiler to skip this
check is in the library. I don't know if we should add
if(p==0)__builtin_unreachable(); somewhere, or create a new
attribute((neverzero)) for the pointer in the vector, or something else, but
the knowledge that the pointer is not zero belongs in the library.

(leaving as unconfirmed and not setting the component to libstdc++ because I'd
like someone else to confirm this)


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

* [Bug c++/35878] Useless NULL pointer check when constructing object
       [not found] <bug-35878-4@http.gcc.gnu.org/bugzilla/>
  2013-09-11 12:59 ` [Bug c++/35878] Useless NULL pointer check when constructing object glisse at gcc dot gnu.org
@ 2013-09-11 13:39 ` redi at gcc dot gnu.org
  2013-09-11 16:58 ` [Bug libstdc++/35878] " glisse at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-09-11 13:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #2)
> The only place I can think of where we could tell the compiler to skip this
> check is in the library. I don't know if we should add
> if(p==0)__builtin_unreachable(); somewhere, or create a new
> attribute((neverzero)) for the pointer in the vector, or something else, but
> the knowledge that the pointer is not zero belongs in the library.

Yes, I'm inclined to agree.


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

* [Bug libstdc++/35878] Useless NULL pointer check when constructing object
       [not found] <bug-35878-4@http.gcc.gnu.org/bugzilla/>
  2013-09-11 12:59 ` [Bug c++/35878] Useless NULL pointer check when constructing object glisse at gcc dot gnu.org
  2013-09-11 13:39 ` redi at gcc dot gnu.org
@ 2013-09-11 16:58 ` glisse at gcc dot gnu.org
  2013-09-11 19:08 ` redi at gcc dot gnu.org
  2014-11-29 19:40 ` [Bug libstdc++/35878] [LWG 2302] " glisse at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-09-11 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-09-11
          Component|c++                         |libstdc++
     Ever confirmed|0                           |1

--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> ---
Confirming then. Jonathan, you didn't send a mail to the reflectors after your
post on SO, did you? Unless you want to do it, I think I'll send one, just to
make sure there is no hope of removing that check at the core level.


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

* [Bug libstdc++/35878] Useless NULL pointer check when constructing object
       [not found] <bug-35878-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2013-09-11 16:58 ` [Bug libstdc++/35878] " glisse at gcc dot gnu.org
@ 2013-09-11 19:08 ` redi at gcc dot gnu.org
  2014-11-29 19:40 ` [Bug libstdc++/35878] [LWG 2302] " glisse at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-09-11 19:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No, I never got round to sending it to the reflector, but I'd be interested to
hear the committee's views on a change.


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

* [Bug libstdc++/35878] [LWG 2302] Useless NULL pointer check when constructing object
       [not found] <bug-35878-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2013-09-11 19:08 ` redi at gcc dot gnu.org
@ 2014-11-29 19:40 ` glisse at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-11-29 19:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35878

--- Comment #6 from Marc Glisse <glisse at gcc dot gnu.org> ---
LWG marked issue 2302 as pending NAD, but CWG was more helpful and we now have
an official DR so we can patch the front-end:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1748


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

end of thread, other threads:[~2014-11-29 19:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-35878-4@http.gcc.gnu.org/bugzilla/>
2013-09-11 12:59 ` [Bug c++/35878] Useless NULL pointer check when constructing object glisse at gcc dot gnu.org
2013-09-11 13:39 ` redi at gcc dot gnu.org
2013-09-11 16:58 ` [Bug libstdc++/35878] " glisse at gcc dot gnu.org
2013-09-11 19:08 ` redi at gcc dot gnu.org
2014-11-29 19:40 ` [Bug libstdc++/35878] [LWG 2302] " glisse at gcc dot gnu.org

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