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

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

Powered by Google App Engine
This is Rietveld 408576698