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

Side by Side Diff: Source/wtf/OwnPtr.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 | « Source/wtf/OwnArrayPtr.h ('k') | Source/wtf/PassOwnArrayPtr.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, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009, 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 30 matching lines...) Expand all
41 #endif 41 #endif
42 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(OwnPtr); 42 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(OwnPtr);
43 public: 43 public:
44 typedef T ValueType; 44 typedef T ValueType;
45 typedef ValueType* PtrType; 45 typedef ValueType* PtrType;
46 46
47 OwnPtr() : m_ptr(0) { } 47 OwnPtr() : m_ptr(0) { }
48 OwnPtr(std::nullptr_t) : m_ptr(0) { } 48 OwnPtr(std::nullptr_t) : m_ptr(0) { }
49 49
50 // See comment in PassOwnPtr.h for why this takes a const reference. 50 // See comment in PassOwnPtr.h for why this takes a const reference.
51 template<typename U> OwnPtr(const PassOwnPtr<U>& o); 51 template<typename U> OwnPtr(const PassOwnPtr<U>&, EnsurePtrConvertibleAr gDecl(U, T));
52 52
53 #if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES) 53 #if !COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
54 // This copy constructor is used implicitly by gcc when it generates 54 // This copy constructor is used implicitly by gcc when it generates
55 // transients for assigning a PassOwnPtr<T> object to a stack-allocated 55 // transients for assigning a PassOwnPtr<T> object to a stack-allocated
56 // OwnPtr<T> object. It should never be called explicitly and gcc 56 // OwnPtr<T> object. It should never be called explicitly and gcc
57 // should optimize away the constructor when generating code. 57 // should optimize away the constructor when generating code.
58 OwnPtr(const OwnPtr<ValueType>&); 58 OwnPtr(const OwnPtr<ValueType>&);
59 #endif 59 #endif
60 60
61 ~OwnPtr() 61 ~OwnPtr()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // We should never have two OwnPtrs for the same underlying object (othe rwise we'll get 102 // We should never have two OwnPtrs for the same underlying object (othe rwise we'll get
103 // double-destruction), so these equality operators should never be need ed. 103 // double-destruction), so these equality operators should never be need ed.
104 template<typename U> bool operator==(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; } 104 template<typename U> bool operator==(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; }
105 template<typename U> bool operator!=(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; } 105 template<typename U> bool operator!=(const OwnPtr<U>&) { COMPILE_ASSERT( !sizeof(U*), OwnPtrs_should_never_be_equal); return false; }
106 template<typename U> bool operator==(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } 106 template<typename U> bool operator==(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; }
107 template<typename U> bool operator!=(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } 107 template<typename U> bool operator!=(const PassOwnPtr<U>&) { COMPILE_ASS ERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; }
108 108
109 PtrType m_ptr; 109 PtrType m_ptr;
110 }; 110 };
111 111
112 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas sOwnPtr<U>& o) 112 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas sOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T))
113 : m_ptr(o.leakPtr()) 113 : m_ptr(o.leakPtr())
114 { 114 {
115 } 115 }
116 116
117 template<typename T> inline void OwnPtr<T>::clear() 117 template<typename T> inline void OwnPtr<T>::clear()
118 { 118 {
119 PtrType ptr = m_ptr; 119 PtrType ptr = m_ptr;
120 m_ptr = 0; 120 m_ptr = 0;
121 deleteOwnedPtr(ptr); 121 deleteOwnedPtr(ptr);
122 } 122 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr< T>& p) 213 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr< T>& p)
214 { 214 {
215 return p.get(); 215 return p.get();
216 } 216 }
217 217
218 } // namespace WTF 218 } // namespace WTF
219 219
220 using WTF::OwnPtr; 220 using WTF::OwnPtr;
221 221
222 #endif // WTF_OwnPtr_h 222 #endif // WTF_OwnPtr_h
OLDNEW
« no previous file with comments | « Source/wtf/OwnArrayPtr.h ('k') | Source/wtf/PassOwnArrayPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698