Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: Source/wtf/OwnArrayPtr.h

Issue 23531003: Type check when upcasting PassOwnPtr/PassOwnArrayPtr to avoid possible function call ambiguousness (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/wtf/OwnPtr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 21 matching lines...) Expand all
32 template<typename T> class PassOwnArrayPtr; 32 template<typename T> class PassOwnArrayPtr;
33 template<typename T> PassOwnArrayPtr<T> adoptArrayPtr(T*); 33 template<typename T> PassOwnArrayPtr<T> adoptArrayPtr(T*);
34 34
35 template <typename T> class OwnArrayPtr { 35 template <typename T> class OwnArrayPtr {
36 public: 36 public:
37 typedef T* PtrType; 37 typedef T* PtrType;
38 38
39 OwnArrayPtr() : m_ptr(0) { } 39 OwnArrayPtr() : m_ptr(0) { }
40 40
41 // See comment in PassOwnArrayPtr.h for why this takes a const reference. 41 // See comment in PassOwnArrayPtr.h for why this takes a const reference.
42 template<typename U> OwnArrayPtr(const PassOwnArrayPtr<U>& o); 42 template<typename U> OwnArrayPtr(const PassOwnArrayPtr<U>&, EnsurePtrConvert ibleArgDecl(U, T));
43 43
44 // This copy constructor is used implicitly by gcc when it generates 44 // This copy constructor is used implicitly by gcc when it generates
45 // transients for assigning a PassOwnArrayPtr<T> object to a stack-allocated 45 // transients for assigning a PassOwnArrayPtr<T> object to a stack-allocated
46 // OwnArrayPtr<T> object. It should never be called explicitly and gcc 46 // OwnArrayPtr<T> object. It should never be called explicitly and gcc
47 // should optimize away the constructor when generating code. 47 // should optimize away the constructor when generating code.
48 OwnArrayPtr(const OwnArrayPtr<T>&); 48 OwnArrayPtr(const OwnArrayPtr<T>&);
49 49
50 ~OwnArrayPtr() { deleteOwnedArrayPtr(m_ptr); } 50 ~OwnArrayPtr() { deleteOwnedArrayPtr(m_ptr); }
51 51
52 PtrType get() const { return m_ptr; } 52 PtrType get() const { return m_ptr; }
(...skipping 16 matching lines...) Expand all
69 OwnArrayPtr& operator=(const PassOwnArrayPtr<T>&); 69 OwnArrayPtr& operator=(const PassOwnArrayPtr<T>&);
70 OwnArrayPtr& operator=(std::nullptr_t) { clear(); return *this; } 70 OwnArrayPtr& operator=(std::nullptr_t) { clear(); return *this; }
71 template<typename U> OwnArrayPtr& operator=(const PassOwnArrayPtr<U>&); 71 template<typename U> OwnArrayPtr& operator=(const PassOwnArrayPtr<U>&);
72 72
73 void swap(OwnArrayPtr& o) { std::swap(m_ptr, o.m_ptr); } 73 void swap(OwnArrayPtr& o) { std::swap(m_ptr, o.m_ptr); }
74 74
75 private: 75 private:
76 PtrType m_ptr; 76 PtrType m_ptr;
77 }; 77 };
78 78
79 template<typename T> template<typename U> inline OwnArrayPtr<T>::OwnArrayPtr(con st PassOwnArrayPtr<U>& o) 79 template<typename T> template<typename U> inline OwnArrayPtr<T>::OwnArrayPtr(con st PassOwnArrayPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T))
80 : m_ptr(o.leakPtr()) 80 : m_ptr(o.leakPtr())
81 { 81 {
82 } 82 }
83 83
84 template<typename T> inline void OwnArrayPtr<T>::clear() 84 template<typename T> inline void OwnArrayPtr<T>::clear()
85 { 85 {
86 PtrType ptr = m_ptr; 86 PtrType ptr = m_ptr;
87 m_ptr = 0; 87 m_ptr = 0;
88 deleteOwnedArrayPtr(ptr); 88 deleteOwnedArrayPtr(ptr);
89 } 89 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 template <typename T> inline T* getPtr(const OwnArrayPtr<T>& p) 148 template <typename T> inline T* getPtr(const OwnArrayPtr<T>& p)
149 { 149 {
150 return p.get(); 150 return p.get();
151 } 151 }
152 152
153 } // namespace WTF 153 } // namespace WTF
154 154
155 using WTF::OwnArrayPtr; 155 using WTF::OwnArrayPtr;
156 156
157 #endif // WTF_OwnArrayPtr_h 157 #endif // WTF_OwnArrayPtr_h
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/OwnPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698