Bug 47756 - Make a nullptr that works with OwnPtr and RefPtr
Summary: Make a nullptr that works with OwnPtr and RefPtr
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-15 17:02 PDT by Darin Adler
Modified: 2011-01-03 13:14 PST (History)
5 users (show)

See Also:


Attachments
Patch (11.29 KB, patch)
2010-10-15 17:03 PDT, Darin Adler
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2010-10-15 17:02:07 PDT
Make a nullptr that works with OwnPtr and RefPtr
Comment 1 Darin Adler 2010-10-15 17:03:55 PDT
Created attachment 70924 [details]
Patch
Comment 2 Geoffrey Garen 2010-10-15 17:07:39 PDT
Comment on attachment 70924 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=70924&action=review

> JavaScriptCore/wtf/NullPtr.h:34
> +class nullptr_t { };

Would it be better to #ifndef nullptr_t here, to avoid overriding something if it is provided by the compiler?

r=me
Comment 3 Anders Carlsson 2010-10-15 17:11:15 PDT
View in context: https://bugs.webkit.org/attachment.cgi?id=70924&action=review

> JavaScriptCore/wtf/NullPtr.h:35
> +extern nullptr_t nullptr;

To better match the C++0x standard, nullptr_t should be in the std namespace.

> JavaScriptCore/wtf/OwnArrayPtr.h:77
> +    OwnArrayPtr& operator=(const nullptr_t&) { clear(); return *this; }

It would be better if nullptr_t was always passed by value. (For example, the Itanium ABI just ignores empty classes when they're passed by value).
Comment 4 Darin Adler 2010-10-18 09:49:49 PDT
(In reply to comment #2)
> Would it be better to #ifndef nullptr_t here, to avoid overriding something if it is provided by the compiler?

If nullptr_t was a macro, then yes. But it’s not.
Comment 5 Darin Adler 2010-10-18 09:50:11 PDT
(In reply to comment #3)
> To better match the C++0x standard, nullptr_t should be in the std namespace.

Fixed.

> It would be better if nullptr_t was always passed by value. (For example, the Itanium ABI just ignores empty classes when they're passed by value).

Fixed.
Comment 6 Darin Adler 2010-10-18 10:24:19 PDT
Committed r69970: <http://trac.webkit.org/changeset/69970>
Comment 7 WebKit Review Bot 2010-10-18 11:06:29 PDT
http://trac.webkit.org/changeset/69970 might have broken Qt Windows 32-bit Release
Comment 8 Kenneth Rohde Christiansen 2011-01-03 13:12:10 PST
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf details a different enumation of nullptr:

const // this is a const object...
class {
public:
  template<class T> // convertible to any type
    operator T*() const // of null non-member
{ return 0; } // pointer...
  template<class C, class T> // or any type of null
    operator T C::*() const // member pointer...
{ return 0; }
private:
  void operator&() const; // whose address can't be taken
} nullptr = {}; // and whose name is nullptr

Does your implementation work in all these situations?
Comment 9 Darin Adler 2011-01-03 13:13:52 PST
(In reply to comment #8)
> Does your implementation work in all these situations?

No. I don’t think it’s possible to make one that would.

This implementation lets us use nullptr in a limited way in the long time between now and when all compilers used with WebKit have nullptr support.
Comment 10 Darin Adler 2011-01-03 13:14:34 PST
(In reply to comment #9)
> (In reply to comment #8)
> > Does your implementation work in all these situations?
> 
> No. I don’t think it’s possible to make one that would.

Oops, I misunderstood your question.

I think we can definitely put the fancier nullptr_t and nullptr in.