Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 #define MOVE_ONLY_TYPE_FOR_CPP_03(type, rvalue_type) \ | |
| 2 public: \ | |
| 3 struct rvalue_type { \ | |
| 4 explicit rvalue_type(type* object) : object(object) {} \ | |
| 5 type* object; \ | |
| 6 }; \ | |
| 7 type(type&); \ | |
| 8 void operator=(type&); \ | |
| 9 operator rvalue_type() { return rvalue_type(this); } \ | |
| 10 type Pass() { return type(rvalue_type(this)); } \ | |
| 11 typedef void MoveOnlyTypeForCPP03; \ | |
| 12 private: | |
| 13 | |
| 14 namespace base { | |
| 15 template <class T> | |
| 16 class scoped_ptr { | |
| 17 MOVE_ONLY_TYPE_FOR_CPP_03(scoped_ptr, RValue) | |
| 18 public: | |
| 19 typedef T element_type; | |
| 20 scoped_ptr() { } | |
| 21 explicit scoped_ptr(element_type* p) { } | |
| 22 scoped_ptr(RValue rvalue) { } | |
| 23 template <typename U> | |
| 24 scoped_ptr& operator=(scoped_ptr<U> rhs) { return *this; } | |
| 25 element_type* get() const { return 0; } | |
| 26 }; | |
| 27 | |
| 28 template <typename T> | |
| 29 static inline T Passed(T scoper) { | |
| 30 return scoper.Pass(); | |
| 31 } | |
| 32 template <typename T> | |
| 33 static inline T Passed(T* scoper) { | |
| 34 return scoper->Pass(); | |
| 35 } | |
| 36 | |
| 37 } | |
| 
 
awong
2014/09/04 00:29:51
}  // namespace base
 
 | |
| 38 | |
| 39 void f_bad(base::scoped_ptr<int> i, int* p) {} | |
| 40 | |
| 41 void f_ok(base::scoped_ptr<int> i) {} | |
| 42 | |
| 43 int h_bad1(base::scoped_ptr<int> i) { return 0; } | |
| 44 int h_bad2(int* i) { return 0; } | |
| 45 int h(int a, int b) { return 0; } | |
| 46 | |
| 47 void g() { | |
| 48 base::scoped_ptr<int> s; | |
| 49 | |
| 50 f_bad(base::Passed(&s), s.get()); | |
| 51 // FIXME: Do I also have to catch (no &)? | |
| 
 
awong
2014/09/04 00:29:51
Yes, but your syntax is wrong. base::Passed(s.Pass
 
 | |
| 52 //f(base::Passed(s), s.get()); | |
| 53 | |
| 54 // Shouldn't warn. | |
| 55 f_ok(base::Passed(&s)); | |
| 56 | |
| 57 h(h_bad1(base::Passed(&s)), | |
| 58 h_bad2(s.get())); | |
| 59 } | |
| OLD | NEW |