tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestNonStdMove.cpp (3702B)


      1 #include <mozilla/RefPtr.h>
      2 
      3 // we can't include nsCOMPtr.h here, so let's redefine a basic version
      4 template<typename T>
      5 struct nsCOMPtr {
      6  nsCOMPtr() = default;
      7 
      8  template<typename U>
      9  MOZ_IMPLICIT nsCOMPtr(already_AddRefed<U>&& aSrc);
     10 
     11  template<typename U>
     12  nsCOMPtr& operator=(already_AddRefed<U>&& aSrc);
     13 };
     14 
     15 
     16 using namespace mozilla;
     17 
     18 struct RefCountedBase {
     19  void AddRef();
     20  void Release();
     21 
     22  void method_test();
     23 };
     24 
     25 struct RefCountedDerived : RefCountedBase {};
     26 
     27 struct RefCountedBaseHolder {
     28  RefPtr<RefCountedBase> GetRefCountedBase() const {
     29    return mRefCountedBase;
     30  }
     31 
     32 private:
     33  RefPtr<RefCountedBase> mRefCountedBase = MakeRefPtr<RefCountedBase>();
     34 };
     35 
     36 
     37 void test_assign_same_type() {
     38  RefPtr<RefCountedBase> a = MakeRefPtr<RefCountedBase>();
     39  RefPtr<RefCountedBase> b;
     40 
     41  b = a.forget(); // expected-warning {{non-standard move assignment}}
     42 }
     43 
     44 void test_assign_implicit_cast() {
     45  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
     46  RefPtr<RefCountedBase> b;
     47 
     48  b = a.forget(); // expected-warning {{non-standard move assignment}}
     49 }
     50 
     51 void test_assign_different_template() {
     52  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
     53  nsCOMPtr<RefCountedBase> b;
     54 
     55  b = a.forget(); // expected-warning {{non-standard move assignment}}
     56 }
     57 
     58 void test_construct_different_template() {
     59  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
     60  nsCOMPtr<RefCountedBase> b = a.forget(); // expected-warning {{non-standard move construction}}
     61 }
     62 
     63 void test_assign_already_addrefed() {
     64  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
     65  already_AddRefed<RefCountedDerived> b;
     66 
     67  b = a.forget();
     68 }
     69 
     70 void test_construct_already_addrefed() {
     71  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
     72  already_AddRefed<RefCountedDerived> b = a.forget();
     73 }
     74 
     75 void test_construct_same_type() {
     76  RefPtr<RefCountedBase> a = MakeRefPtr<RefCountedBase>();
     77  RefPtr<RefCountedBase> b = a.forget(); // expected-warning {{non-standard move construction}}
     78 }
     79 
     80 void test_construct_implicit_cast() {
     81  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
     82  RefPtr<RefCountedBase> b = a.forget(); // expected-warning {{non-standard move construction}}
     83 }
     84 
     85 void test_construct_brace_same_type() {
     86  RefPtr<RefCountedBase> a = MakeRefPtr<RefCountedBase>();
     87  auto b = RefPtr<RefCountedBase>{a.forget()}; // expected-warning {{non-standard move construction}}
     88 }
     89 
     90 void test_construct_brace_implicit_cast() {
     91  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
     92  auto b = RefPtr<RefCountedBase>{a.forget()}; // expected-warning {{non-standard move construction}}
     93 }
     94 
     95 void test_construct_function_style_same_type() {
     96  RefPtr<RefCountedBase> a = MakeRefPtr<RefCountedBase>();
     97  auto b = RefPtr<RefCountedBase>(a.forget()); // expected-warning {{non-standard move construction}}
     98 }
     99 
    100 void test_construct_function_style_implicit_cast() {
    101  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
    102  auto b = RefPtr<RefCountedBase>(a.forget());  // expected-warning {{non-standard move construction}}
    103 }
    104 
    105 void test_construct_result_type() {
    106  RefPtr<RefCountedBase> a = MakeRefPtr<RefCountedBase>();
    107  already_AddRefed<RefCountedBase> b = a.forget();
    108 }
    109 
    110 void test_construct_implicitly_cast_result_type() {
    111  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
    112  already_AddRefed<RefCountedBase> b = a.forget();
    113 }
    114 
    115 void foo(already_AddRefed<RefCountedBase>&& aArg);
    116 
    117 void test_call_with_result_type() {
    118  RefPtr<RefCountedBase> a = MakeRefPtr<RefCountedBase>();
    119  foo(a.forget());
    120 }
    121 
    122 void test_call_with_implicitly_cast_result_type() {
    123  RefPtr<RefCountedDerived> a = MakeRefPtr<RefCountedDerived>();
    124  foo(a.forget());
    125 }