| File: | root/firefox-clang/mfbt/tests/TestUniquePtr.cpp |
| Warning: | line 434, column 3 Method called on moved-from object 'n1' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public | |||
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, | |||
| 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ | |||
| 4 | ||||
| 5 | #include <stddef.h> | |||
| 6 | ||||
| 7 | #include <memory> // For unique_ptr | |||
| 8 | #include <type_traits> | |||
| 9 | #include <utility> | |||
| 10 | ||||
| 11 | #include "mozilla/Assertions.h" | |||
| 12 | #include "mozilla/UniquePtr.h" | |||
| 13 | #include "mozilla/UniquePtrExtensions.h" | |||
| 14 | #include "mozilla/Vector.h" | |||
| 15 | ||||
| 16 | using mozilla::DefaultDelete; | |||
| 17 | using mozilla::MakeUnique; | |||
| 18 | using mozilla::UniqueFreePtr; | |||
| 19 | using mozilla::UniquePtr; | |||
| 20 | using mozilla::Vector; | |||
| 21 | ||||
| 22 | #define CHECK(c)do { bool cond = !!(c); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "c" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp", 22); do { } while (false); do { MOZ_CrashSequence(__null, 22 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false) \ | |||
| 23 | do { \ | |||
| 24 | bool cond = !!(c); \ | |||
| 25 | MOZ_RELEASE_ASSERT(cond, "Test failed: " #c)do { static_assert( mozilla::detail::AssertionConditionType< decltype(cond)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " #c ")" , "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp", 25); do { } while (false); do { MOZ_CrashSequence(__null, 25); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); \ | |||
| 26 | } while (false) | |||
| 27 | ||||
| 28 | typedef UniquePtr<int> NewInt; | |||
| 29 | static_assert(sizeof(NewInt) == sizeof(int*), "stored most efficiently"); | |||
| 30 | ||||
| 31 | static size_t gADestructorCalls = 0; | |||
| 32 | ||||
| 33 | struct A { | |||
| 34 | public: | |||
| 35 | A() : mX(0) {} | |||
| 36 | virtual ~A() { gADestructorCalls++; } | |||
| 37 | ||||
| 38 | int mX; | |||
| 39 | }; | |||
| 40 | ||||
| 41 | static size_t gBDestructorCalls = 0; | |||
| 42 | ||||
| 43 | struct B : public A { | |||
| 44 | public: | |||
| 45 | B() : mY(1) {} | |||
| 46 | ~B() { gBDestructorCalls++; } | |||
| 47 | ||||
| 48 | int mY; | |||
| 49 | }; | |||
| 50 | ||||
| 51 | typedef UniquePtr<A> UniqueA; | |||
| 52 | typedef UniquePtr<B, UniqueA::deleter_type> UniqueB; // permit interconversion | |||
| 53 | ||||
| 54 | static_assert(sizeof(UniqueA) == sizeof(A*), "stored most efficiently"); | |||
| 55 | static_assert(sizeof(UniqueB) == sizeof(B*), "stored most efficiently"); | |||
| 56 | ||||
| 57 | struct DeleterSubclass : UniqueA::deleter_type {}; | |||
| 58 | ||||
| 59 | typedef UniquePtr<B, DeleterSubclass> UniqueC; | |||
| 60 | static_assert(sizeof(UniqueC) == sizeof(B*), "stored most efficiently"); | |||
| 61 | ||||
| 62 | static UniqueA ReturnUniqueA() { return UniqueA(new B); } | |||
| 63 | ||||
| 64 | static UniqueA ReturnLocalA() { | |||
| 65 | UniqueA a(new A); | |||
| 66 | return a; | |||
| 67 | } | |||
| 68 | ||||
| 69 | static void TestDeleterType() { | |||
| 70 | // Make sure UniquePtr will use its deleter's pointer type if it defines one. | |||
| 71 | typedef int* Ptr; | |||
| 72 | struct Deleter { | |||
| 73 | typedef Ptr pointer; | |||
| 74 | Deleter() = default; | |||
| 75 | void operator()(int* p) { delete p; } | |||
| 76 | }; | |||
| 77 | UniquePtr<Ptr, Deleter> u(new int, Deleter()); | |||
| 78 | } | |||
| 79 | ||||
| 80 | static bool TestDefaultFreeGuts() { | |||
| 81 | static_assert(std::is_same_v<NewInt::deleter_type, DefaultDelete<int> >, | |||
| 82 | "weird deleter?"); | |||
| 83 | ||||
| 84 | NewInt n1(new int); | |||
| 85 | CHECK(n1)do { bool cond = !!(n1); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 85); do { } while (false); do { MOZ_CrashSequence(__null, 85 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 86 | CHECK(n1.get() != nullptr)do { bool cond = !!(n1.get() != nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() != nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 86); do { } while (false); do { MOZ_CrashSequence(__null, 86 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 87 | ||||
| 88 | n1 = nullptr; | |||
| 89 | CHECK(!n1)do { bool cond = !!(!n1); do { static_assert( mozilla::detail ::AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "!n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 89); do { } while (false); do { MOZ_CrashSequence(__null, 89 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 90 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 90); do { } while (false); do { MOZ_CrashSequence(__null, 90 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 91 | ||||
| 92 | int* p1 = new int; | |||
| 93 | n1.reset(p1); | |||
| 94 | CHECK(n1)do { bool cond = !!(n1); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 94); do { } while (false); do { MOZ_CrashSequence(__null, 94 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 95 | NewInt n2(std::move(n1)); | |||
| 96 | CHECK(!n1)do { bool cond = !!(!n1); do { static_assert( mozilla::detail ::AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "!n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 96); do { } while (false); do { MOZ_CrashSequence(__null, 96 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 97 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 97); do { } while (false); do { MOZ_CrashSequence(__null, 97 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 98 | CHECK(n2.get() == p1)do { bool cond = !!(n2.get() == p1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 98); do { } while (false); do { MOZ_CrashSequence(__null, 98 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 99 | ||||
| 100 | std::swap(n1, n2); | |||
| 101 | CHECK(n1.get() == p1)do { bool cond = !!(n1.get() == p1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 101); do { } while (false); do { MOZ_CrashSequence(__null, 101 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 102 | CHECK(n2.get() == nullptr)do { bool cond = !!(n2.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 102); do { } while (false); do { MOZ_CrashSequence(__null, 102 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 103 | ||||
| 104 | n1.swap(n2); | |||
| 105 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 105); do { } while (false); do { MOZ_CrashSequence(__null, 105 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 106 | CHECK(n2.get() == p1)do { bool cond = !!(n2.get() == p1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 106); do { } while (false); do { MOZ_CrashSequence(__null, 106 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 107 | delete n2.release(); | |||
| 108 | ||||
| 109 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 109); do { } while (false); do { MOZ_CrashSequence(__null, 109 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 110 | CHECK(n2 == nullptr)do { bool cond = !!(n2 == nullptr); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2 == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 110); do { } while (false); do { MOZ_CrashSequence(__null, 110 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 111 | CHECK(nullptr == n2)do { bool cond = !!(nullptr == n2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "nullptr == n2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 111); do { } while (false); do { MOZ_CrashSequence(__null, 111 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 112 | ||||
| 113 | int* p2 = new int; | |||
| 114 | int* p3 = new int; | |||
| 115 | n1.reset(p2); | |||
| 116 | n2.reset(p3); | |||
| 117 | CHECK(n1.get() == p2)do { bool cond = !!(n1.get() == p2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 117); do { } while (false); do { MOZ_CrashSequence(__null, 117 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 118 | CHECK(n2.get() == p3)do { bool cond = !!(n2.get() == p3); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 118); do { } while (false); do { MOZ_CrashSequence(__null, 118 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 119 | ||||
| 120 | n1.swap(n2); | |||
| 121 | CHECK(n2 != nullptr)do { bool cond = !!(n2 != nullptr); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2 != nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 121); do { } while (false); do { MOZ_CrashSequence(__null, 121 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 122 | CHECK(nullptr != n2)do { bool cond = !!(nullptr != n2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "nullptr != n2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 122); do { } while (false); do { MOZ_CrashSequence(__null, 122 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 123 | CHECK(n2.get() == p2)do { bool cond = !!(n2.get() == p2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 123); do { } while (false); do { MOZ_CrashSequence(__null, 123 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 124 | CHECK(n1.get() == p3)do { bool cond = !!(n1.get() == p3); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == p3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 124); do { } while (false); do { MOZ_CrashSequence(__null, 124 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 125 | ||||
| 126 | UniqueA a1; | |||
| 127 | CHECK(a1 == nullptr)do { bool cond = !!(a1 == nullptr); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "a1 == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 127); do { } while (false); do { MOZ_CrashSequence(__null, 127 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 128 | a1.reset(new A); | |||
| 129 | CHECK(gADestructorCalls == 0)do { bool cond = !!(gADestructorCalls == 0); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 129); do { } while (false); do { MOZ_CrashSequence(__null, 129 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 130 | CHECK(a1->mX == 0)do { bool cond = !!(a1->mX == 0); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "a1->mX == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 130); do { } while (false); do { MOZ_CrashSequence(__null, 130 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 131 | ||||
| 132 | B* bp1 = new B; | |||
| 133 | bp1->mX = 5; | |||
| 134 | CHECK(gBDestructorCalls == 0)do { bool cond = !!(gBDestructorCalls == 0); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 134); do { } while (false); do { MOZ_CrashSequence(__null, 134 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 135 | a1.reset(bp1); | |||
| 136 | CHECK(gADestructorCalls == 1)do { bool cond = !!(gADestructorCalls == 1); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 136); do { } while (false); do { MOZ_CrashSequence(__null, 136 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 137 | CHECK(a1->mX == 5)do { bool cond = !!(a1->mX == 5); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "a1->mX == 5" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 137); do { } while (false); do { MOZ_CrashSequence(__null, 137 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 138 | a1.reset(nullptr); | |||
| 139 | CHECK(gADestructorCalls == 2)do { bool cond = !!(gADestructorCalls == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 139); do { } while (false); do { MOZ_CrashSequence(__null, 139 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 140 | CHECK(gBDestructorCalls == 1)do { bool cond = !!(gBDestructorCalls == 1); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 140); do { } while (false); do { MOZ_CrashSequence(__null, 140 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 141 | ||||
| 142 | B* bp2 = new B; | |||
| 143 | UniqueB b1(bp2); | |||
| 144 | UniqueA a2(nullptr); | |||
| 145 | a2 = std::move(b1); | |||
| 146 | CHECK(gADestructorCalls == 2)do { bool cond = !!(gADestructorCalls == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 146); do { } while (false); do { MOZ_CrashSequence(__null, 146 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 147 | CHECK(gBDestructorCalls == 1)do { bool cond = !!(gBDestructorCalls == 1); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 147); do { } while (false); do { MOZ_CrashSequence(__null, 147 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 148 | ||||
| 149 | UniqueA a3(std::move(a2)); | |||
| 150 | a3 = nullptr; | |||
| 151 | CHECK(gADestructorCalls == 3)do { bool cond = !!(gADestructorCalls == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 151); do { } while (false); do { MOZ_CrashSequence(__null, 151 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 152 | CHECK(gBDestructorCalls == 2)do { bool cond = !!(gBDestructorCalls == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 152); do { } while (false); do { MOZ_CrashSequence(__null, 152 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 153 | ||||
| 154 | B* bp3 = new B; | |||
| 155 | bp3->mX = 42; | |||
| 156 | UniqueB b2(bp3); | |||
| 157 | UniqueA a4(std::move(b2)); | |||
| 158 | CHECK(b2.get() == nullptr)do { bool cond = !!(b2.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "b2.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 158); do { } while (false); do { MOZ_CrashSequence(__null, 158 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 159 | CHECK((*a4).mX == 42)do { bool cond = !!((*a4).mX == 42); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "(*a4).mX == 42" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 159); do { } while (false); do { MOZ_CrashSequence(__null, 159 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 160 | CHECK(gADestructorCalls == 3)do { bool cond = !!(gADestructorCalls == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 160); do { } while (false); do { MOZ_CrashSequence(__null, 160 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 161 | CHECK(gBDestructorCalls == 2)do { bool cond = !!(gBDestructorCalls == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 161); do { } while (false); do { MOZ_CrashSequence(__null, 161 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 162 | ||||
| 163 | UniqueA a5(new A); | |||
| 164 | UniqueB b3(new B); | |||
| 165 | a5 = std::move(b3); | |||
| 166 | CHECK(gADestructorCalls == 4)do { bool cond = !!(gADestructorCalls == 4); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 4" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 166); do { } while (false); do { MOZ_CrashSequence(__null, 166 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 167 | CHECK(gBDestructorCalls == 2)do { bool cond = !!(gBDestructorCalls == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 167); do { } while (false); do { MOZ_CrashSequence(__null, 167 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 168 | ||||
| 169 | ReturnUniqueA(); | |||
| 170 | CHECK(gADestructorCalls == 5)do { bool cond = !!(gADestructorCalls == 5); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 5" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 170); do { } while (false); do { MOZ_CrashSequence(__null, 170 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 171 | CHECK(gBDestructorCalls == 3)do { bool cond = !!(gBDestructorCalls == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 171); do { } while (false); do { MOZ_CrashSequence(__null, 171 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 172 | ||||
| 173 | ReturnLocalA(); | |||
| 174 | CHECK(gADestructorCalls == 6)do { bool cond = !!(gADestructorCalls == 6); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 6" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 174); do { } while (false); do { MOZ_CrashSequence(__null, 174 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 175 | CHECK(gBDestructorCalls == 3)do { bool cond = !!(gBDestructorCalls == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 175); do { } while (false); do { MOZ_CrashSequence(__null, 175 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 176 | ||||
| 177 | UniqueA a6(ReturnLocalA()); | |||
| 178 | a6 = nullptr; | |||
| 179 | CHECK(gADestructorCalls == 7)do { bool cond = !!(gADestructorCalls == 7); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 7" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 179); do { } while (false); do { MOZ_CrashSequence(__null, 179 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 180 | CHECK(gBDestructorCalls == 3)do { bool cond = !!(gBDestructorCalls == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 180); do { } while (false); do { MOZ_CrashSequence(__null, 180 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 181 | ||||
| 182 | UniqueC c1(new B); | |||
| 183 | UniqueA a7(new B); | |||
| 184 | a7 = std::move(c1); | |||
| 185 | CHECK(gADestructorCalls == 8)do { bool cond = !!(gADestructorCalls == 8); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 8" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 185); do { } while (false); do { MOZ_CrashSequence(__null, 185 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 186 | CHECK(gBDestructorCalls == 4)do { bool cond = !!(gBDestructorCalls == 4); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 4" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 186); do { } while (false); do { MOZ_CrashSequence(__null, 186 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 187 | ||||
| 188 | c1.reset(new B); | |||
| 189 | ||||
| 190 | UniqueA a8(std::move(c1)); | |||
| 191 | CHECK(gADestructorCalls == 8)do { bool cond = !!(gADestructorCalls == 8); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 8" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 191); do { } while (false); do { MOZ_CrashSequence(__null, 191 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 192 | CHECK(gBDestructorCalls == 4)do { bool cond = !!(gBDestructorCalls == 4); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 4" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 192); do { } while (false); do { MOZ_CrashSequence(__null, 192 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 193 | ||||
| 194 | // These smart pointers still own B resources. | |||
| 195 | CHECK(a4)do { bool cond = !!(a4); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "a4" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 195); do { } while (false); do { MOZ_CrashSequence(__null, 195 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 196 | CHECK(a5)do { bool cond = !!(a5); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "a5" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 196); do { } while (false); do { MOZ_CrashSequence(__null, 196 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 197 | CHECK(a7)do { bool cond = !!(a7); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "a7" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 197); do { } while (false); do { MOZ_CrashSequence(__null, 197 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 198 | CHECK(a8)do { bool cond = !!(a8); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "a8" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 198); do { } while (false); do { MOZ_CrashSequence(__null, 198 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 199 | return true; | |||
| 200 | } | |||
| 201 | ||||
| 202 | static bool TestDefaultFree() { | |||
| 203 | CHECK(TestDefaultFreeGuts())do { bool cond = !!(TestDefaultFreeGuts()); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "TestDefaultFreeGuts()" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 203); do { } while (false); do { MOZ_CrashSequence(__null, 203 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 204 | CHECK(gADestructorCalls == 12)do { bool cond = !!(gADestructorCalls == 12); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 12" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 204); do { } while (false); do { MOZ_CrashSequence(__null, 204 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 205 | CHECK(gBDestructorCalls == 8)do { bool cond = !!(gBDestructorCalls == 8); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 8" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 205); do { } while (false); do { MOZ_CrashSequence(__null, 205 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 206 | return true; | |||
| 207 | } | |||
| 208 | ||||
| 209 | static size_t FreeClassCounter = 0; | |||
| 210 | ||||
| 211 | struct FreeClass { | |||
| 212 | public: | |||
| 213 | FreeClass() = default; | |||
| 214 | ||||
| 215 | void operator()(int* aPtr) { | |||
| 216 | FreeClassCounter++; | |||
| 217 | delete aPtr; | |||
| 218 | } | |||
| 219 | }; | |||
| 220 | ||||
| 221 | typedef UniquePtr<int, FreeClass> NewIntCustom; | |||
| 222 | static_assert(sizeof(NewIntCustom) == sizeof(int*), "stored most efficiently"); | |||
| 223 | ||||
| 224 | static bool TestFreeClass() { | |||
| 225 | CHECK(FreeClassCounter == 0)do { bool cond = !!(FreeClassCounter == 0); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 225); do { } while (false); do { MOZ_CrashSequence(__null, 225 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 226 | { | |||
| 227 | NewIntCustom n1(new int); | |||
| 228 | CHECK(FreeClassCounter == 0)do { bool cond = !!(FreeClassCounter == 0); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 228); do { } while (false); do { MOZ_CrashSequence(__null, 228 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 229 | } | |||
| 230 | CHECK(FreeClassCounter == 1)do { bool cond = !!(FreeClassCounter == 1); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 230); do { } while (false); do { MOZ_CrashSequence(__null, 230 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 231 | ||||
| 232 | NewIntCustom n2; | |||
| 233 | { | |||
| 234 | NewIntCustom n3(new int); | |||
| 235 | CHECK(FreeClassCounter == 1)do { bool cond = !!(FreeClassCounter == 1); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 235); do { } while (false); do { MOZ_CrashSequence(__null, 235 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 236 | n2 = std::move(n3); | |||
| 237 | } | |||
| 238 | CHECK(FreeClassCounter == 1)do { bool cond = !!(FreeClassCounter == 1); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 238); do { } while (false); do { MOZ_CrashSequence(__null, 238 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 239 | n2 = nullptr; | |||
| 240 | CHECK(FreeClassCounter == 2)do { bool cond = !!(FreeClassCounter == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 240); do { } while (false); do { MOZ_CrashSequence(__null, 240 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 241 | ||||
| 242 | n2.reset(nullptr); | |||
| 243 | CHECK(FreeClassCounter == 2)do { bool cond = !!(FreeClassCounter == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 243); do { } while (false); do { MOZ_CrashSequence(__null, 243 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 244 | n2.reset(new int); | |||
| 245 | n2.reset(); | |||
| 246 | CHECK(FreeClassCounter == 3)do { bool cond = !!(FreeClassCounter == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 246); do { } while (false); do { MOZ_CrashSequence(__null, 246 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 247 | ||||
| 248 | NewIntCustom n4(new int, FreeClass()); | |||
| 249 | CHECK(FreeClassCounter == 3)do { bool cond = !!(FreeClassCounter == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 249); do { } while (false); do { MOZ_CrashSequence(__null, 249 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 250 | n4.reset(new int); | |||
| 251 | CHECK(FreeClassCounter == 4)do { bool cond = !!(FreeClassCounter == 4); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 4" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 251); do { } while (false); do { MOZ_CrashSequence(__null, 251 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 252 | n4.reset(); | |||
| 253 | CHECK(FreeClassCounter == 5)do { bool cond = !!(FreeClassCounter == 5); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 5" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 253); do { } while (false); do { MOZ_CrashSequence(__null, 253 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 254 | ||||
| 255 | FreeClass f; | |||
| 256 | NewIntCustom n5(new int, f); | |||
| 257 | CHECK(FreeClassCounter == 5)do { bool cond = !!(FreeClassCounter == 5); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 5" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 257); do { } while (false); do { MOZ_CrashSequence(__null, 257 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 258 | int* p = n5.release(); | |||
| 259 | CHECK(FreeClassCounter == 5)do { bool cond = !!(FreeClassCounter == 5); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "FreeClassCounter == 5" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 259); do { } while (false); do { MOZ_CrashSequence(__null, 259 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 260 | delete p; | |||
| 261 | ||||
| 262 | return true; | |||
| 263 | } | |||
| 264 | ||||
| 265 | typedef UniquePtr<int, DefaultDelete<int>&> IntDeleterRef; | |||
| 266 | typedef UniquePtr<A, DefaultDelete<A>&> ADeleterRef; | |||
| 267 | typedef UniquePtr<B, DefaultDelete<A>&> BDeleterRef; | |||
| 268 | ||||
| 269 | static_assert(sizeof(IntDeleterRef) > sizeof(int*), | |||
| 270 | "has to be heavier than an int* to store the reference"); | |||
| 271 | static_assert(sizeof(ADeleterRef) > sizeof(A*), | |||
| 272 | "has to be heavier than an A* to store the reference"); | |||
| 273 | static_assert(sizeof(BDeleterRef) > sizeof(int*), | |||
| 274 | "has to be heavier than a B* to store the reference"); | |||
| 275 | ||||
| 276 | static bool TestReferenceDeleterGuts() { | |||
| 277 | DefaultDelete<int> delInt; | |||
| 278 | IntDeleterRef id1(new int, delInt); | |||
| 279 | ||||
| 280 | IntDeleterRef id2(std::move(id1)); | |||
| 281 | CHECK(id1 == nullptr)do { bool cond = !!(id1 == nullptr); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "id1 == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 281); do { } while (false); do { MOZ_CrashSequence(__null, 281 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 282 | CHECK(nullptr != id2)do { bool cond = !!(nullptr != id2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "nullptr != id2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 282); do { } while (false); do { MOZ_CrashSequence(__null, 282 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 283 | CHECK(&id1.get_deleter() == &id2.get_deleter())do { bool cond = !!(&id1.get_deleter() == &id2.get_deleter ()); do { static_assert( mozilla::detail::AssertionConditionType <decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "&id1.get_deleter() == &id2.get_deleter()" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 283); do { } while (false); do { MOZ_CrashSequence(__null, 283 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 284 | ||||
| 285 | IntDeleterRef id3(std::move(id2)); | |||
| 286 | ||||
| 287 | DefaultDelete<A> delA; | |||
| 288 | ADeleterRef a1(new A, delA); | |||
| 289 | a1.reset(nullptr); | |||
| 290 | a1.reset(new B); | |||
| 291 | a1 = nullptr; | |||
| 292 | ||||
| 293 | BDeleterRef b1(new B, delA); | |||
| 294 | a1 = std::move(b1); | |||
| 295 | ||||
| 296 | BDeleterRef b2(new B, delA); | |||
| 297 | ||||
| 298 | ADeleterRef a2(std::move(b2)); | |||
| 299 | ||||
| 300 | return true; | |||
| 301 | } | |||
| 302 | ||||
| 303 | static bool TestReferenceDeleter() { | |||
| 304 | gADestructorCalls = 0; | |||
| 305 | gBDestructorCalls = 0; | |||
| 306 | ||||
| 307 | CHECK(TestReferenceDeleterGuts())do { bool cond = !!(TestReferenceDeleterGuts()); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "TestReferenceDeleterGuts()" ")" , "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp", 307); do { } while (false); do { MOZ_CrashSequence(__null, 307); __attribute__ ((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 308 | ||||
| 309 | CHECK(gADestructorCalls == 4)do { bool cond = !!(gADestructorCalls == 4); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 4" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 309); do { } while (false); do { MOZ_CrashSequence(__null, 309 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 310 | CHECK(gBDestructorCalls == 3)do { bool cond = !!(gBDestructorCalls == 3); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 310); do { } while (false); do { MOZ_CrashSequence(__null, 310 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 311 | ||||
| 312 | gADestructorCalls = 0; | |||
| 313 | gBDestructorCalls = 0; | |||
| 314 | return true; | |||
| 315 | } | |||
| 316 | ||||
| 317 | struct Free { | |||
| 318 | void operator()(void* aPtr) { free(aPtr); } | |||
| 319 | }; | |||
| 320 | ||||
| 321 | static size_t DeleteIntFunctionCallCount = 0; | |||
| 322 | struct DeleteIntFunction { | |||
| 323 | void operator()(void* aPtr) { | |||
| 324 | DeleteIntFunctionCallCount++; | |||
| 325 | delete[] static_cast<int*>(aPtr); | |||
| 326 | } | |||
| 327 | }; | |||
| 328 | ||||
| 329 | static void SetMallocedInt(UniquePtr<int, Free>& aPtr, int aI) { | |||
| 330 | int* newPtr = static_cast<int*>(malloc(sizeof(int))); | |||
| 331 | *newPtr = aI; | |||
| 332 | aPtr.reset(newPtr); | |||
| 333 | } | |||
| 334 | ||||
| 335 | static UniquePtr<int, Free> MallocedInt(int aI) { | |||
| 336 | UniquePtr<int, Free> ptr(static_cast<int*>(malloc(sizeof(int))), Free{}); | |||
| 337 | *ptr = aI; | |||
| 338 | return ptr; | |||
| 339 | } | |||
| 340 | static bool TestFunctionReferenceDeleter() { | |||
| 341 | // Look for allocator mismatches and leaks to verify these bits | |||
| 342 | UniquePtr<int, Free> i1(MallocedInt(17)); | |||
| 343 | CHECK(*i1 == 17)do { bool cond = !!(*i1 == 17); do { static_assert( mozilla:: detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "*i1 == 17" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 343); do { } while (false); do { MOZ_CrashSequence(__null, 343 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 344 | ||||
| 345 | SetMallocedInt(i1, 42); | |||
| 346 | CHECK(*i1 == 42)do { bool cond = !!(*i1 == 42); do { static_assert( mozilla:: detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "*i1 == 42" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 346); do { } while (false); do { MOZ_CrashSequence(__null, 346 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 347 | ||||
| 348 | // These bits use a custom deleter so we can instrument deletion. | |||
| 349 | { | |||
| 350 | UniquePtr<int, DeleteIntFunction> i2 = | |||
| 351 | UniquePtr<int, DeleteIntFunction>(new int[42], DeleteIntFunction{}); | |||
| 352 | CHECK(DeleteIntFunctionCallCount == 0)do { bool cond = !!(DeleteIntFunctionCallCount == 0); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "DeleteIntFunctionCallCount == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp", 352 ); do { } while (false); do { MOZ_CrashSequence(__null, 352); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 353 | ||||
| 354 | i2.reset(new int[76]); | |||
| 355 | CHECK(DeleteIntFunctionCallCount == 1)do { bool cond = !!(DeleteIntFunctionCallCount == 1); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "DeleteIntFunctionCallCount == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp", 355 ); do { } while (false); do { MOZ_CrashSequence(__null, 355); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 356 | } | |||
| 357 | ||||
| 358 | CHECK(DeleteIntFunctionCallCount == 2)do { bool cond = !!(DeleteIntFunctionCallCount == 2); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "DeleteIntFunctionCallCount == 2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp", 358 ); do { } while (false); do { MOZ_CrashSequence(__null, 358); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 359 | ||||
| 360 | return true; | |||
| 361 | } | |||
| 362 | ||||
| 363 | template <typename T> | |||
| 364 | struct AppendNullptrTwice { | |||
| 365 | AppendNullptrTwice() = default; | |||
| 366 | ||||
| 367 | bool operator()(Vector<T>& vec) { | |||
| 368 | CHECK(vec.append(nullptr))do { bool cond = !!(vec.append(nullptr)); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "vec.append(nullptr)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 368); do { } while (false); do { MOZ_CrashSequence(__null, 368 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 369 | CHECK(vec.append(nullptr))do { bool cond = !!(vec.append(nullptr)); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "vec.append(nullptr)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 369); do { } while (false); do { MOZ_CrashSequence(__null, 369 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 370 | return true; | |||
| 371 | } | |||
| 372 | }; | |||
| 373 | ||||
| 374 | static size_t AAfter; | |||
| 375 | static size_t BAfter; | |||
| 376 | ||||
| 377 | static bool TestVectorGuts() { | |||
| 378 | Vector<UniqueA> vec; | |||
| 379 | CHECK(vec.append(new B))do { bool cond = !!(vec.append(new B)); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "vec.append(new B)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 379); do { } while (false); do { MOZ_CrashSequence(__null, 379 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 380 | CHECK(vec.append(new A))do { bool cond = !!(vec.append(new A)); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "vec.append(new A)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 380); do { } while (false); do { MOZ_CrashSequence(__null, 380 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 381 | CHECK(AppendNullptrTwice<UniqueA>()(vec))do { bool cond = !!(AppendNullptrTwice<UniqueA>()(vec)) ; do { static_assert( mozilla::detail::AssertionConditionType <decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "AppendNullptrTwice<UniqueA>()(vec)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 381); do { } while (false); do { MOZ_CrashSequence(__null, 381 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 382 | CHECK(vec.append(new B))do { bool cond = !!(vec.append(new B)); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "vec.append(new B)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 382); do { } while (false); do { MOZ_CrashSequence(__null, 382 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 383 | ||||
| 384 | size_t initialLength = vec.length(); | |||
| 385 | ||||
| 386 | UniqueA* begin = vec.begin(); | |||
| 387 | bool appendA = true; | |||
| 388 | do { | |||
| 389 | CHECK(appendA ? vec.append(new A) : vec.append(new B))do { bool cond = !!(appendA ? vec.append(new A) : vec.append( new B)); do { static_assert( mozilla::detail::AssertionConditionType <decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "appendA ? vec.append(new A) : vec.append(new B)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 389); do { } while (false); do { MOZ_CrashSequence(__null, 389 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 390 | appendA = !appendA; | |||
| 391 | } while (begin == vec.begin()); | |||
| 392 | ||||
| 393 | size_t numAppended = vec.length() - initialLength; | |||
| 394 | ||||
| 395 | BAfter = numAppended / 2; | |||
| 396 | AAfter = numAppended - numAppended / 2; | |||
| 397 | ||||
| 398 | CHECK(gADestructorCalls == 0)do { bool cond = !!(gADestructorCalls == 0); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gADestructorCalls == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 398); do { } while (false); do { MOZ_CrashSequence(__null, 398 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 399 | CHECK(gBDestructorCalls == 0)do { bool cond = !!(gBDestructorCalls == 0); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 399); do { } while (false); do { MOZ_CrashSequence(__null, 399 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 400 | return true; | |||
| 401 | } | |||
| 402 | ||||
| 403 | static bool TestVector() { | |||
| 404 | gADestructorCalls = 0; | |||
| 405 | gBDestructorCalls = 0; | |||
| 406 | ||||
| 407 | CHECK(TestVectorGuts())do { bool cond = !!(TestVectorGuts()); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "TestVectorGuts()" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 407); do { } while (false); do { MOZ_CrashSequence(__null, 407 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 408 | ||||
| 409 | CHECK(gADestructorCalls == 3 + AAfter + BAfter)do { bool cond = !!(gADestructorCalls == 3 + AAfter + BAfter) ; do { static_assert( mozilla::detail::AssertionConditionType <decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "gADestructorCalls == 3 + AAfter + BAfter" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 409); do { } while (false); do { MOZ_CrashSequence(__null, 409 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 410 | CHECK(gBDestructorCalls == 2 + BAfter)do { bool cond = !!(gBDestructorCalls == 2 + BAfter); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "gBDestructorCalls == 2 + BAfter" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp", 410 ); do { } while (false); do { MOZ_CrashSequence(__null, 410); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 411 | return true; | |||
| 412 | } | |||
| 413 | ||||
| 414 | typedef UniquePtr<int[]> IntArray; | |||
| 415 | static_assert(sizeof(IntArray) == sizeof(int*), "stored most efficiently"); | |||
| 416 | ||||
| 417 | static bool TestArray() { | |||
| 418 | static_assert(std::is_same_v<IntArray::deleter_type, DefaultDelete<int[]> >, | |||
| 419 | "weird deleter?"); | |||
| 420 | ||||
| 421 | IntArray n1(new int[5]); | |||
| 422 | CHECK(n1)do { bool cond = !!(n1); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 422); do { } while (false); do { MOZ_CrashSequence(__null, 422 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| ||||
| 423 | CHECK(n1.get() != nullptr)do { bool cond = !!(n1.get() != nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() != nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 423); do { } while (false); do { MOZ_CrashSequence(__null, 423 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 424 | ||||
| 425 | n1 = nullptr; | |||
| 426 | CHECK(!n1)do { bool cond = !!(!n1); do { static_assert( mozilla::detail ::AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "!n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 426); do { } while (false); do { MOZ_CrashSequence(__null, 426 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 427 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 427); do { } while (false); do { MOZ_CrashSequence(__null, 427 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 428 | ||||
| 429 | int* p1 = new int[42]; | |||
| 430 | n1.reset(p1); | |||
| 431 | CHECK(n1)do { bool cond = !!(n1); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 431); do { } while (false); do { MOZ_CrashSequence(__null, 431 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 432 | IntArray n2(std::move(n1)); | |||
| 433 | CHECK(!n1)do { bool cond = !!(!n1); do { static_assert( mozilla::detail ::AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "!n1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 433); do { } while (false); do { MOZ_CrashSequence(__null, 433 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 434 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 434); do { } while (false); do { MOZ_CrashSequence(__null, 434 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| ||||
| 435 | CHECK(n2.get() == p1)do { bool cond = !!(n2.get() == p1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 435); do { } while (false); do { MOZ_CrashSequence(__null, 435 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 436 | ||||
| 437 | std::swap(n1, n2); | |||
| 438 | CHECK(n1.get() == p1)do { bool cond = !!(n1.get() == p1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 438); do { } while (false); do { MOZ_CrashSequence(__null, 438 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 439 | CHECK(n2.get() == nullptr)do { bool cond = !!(n2.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 439); do { } while (false); do { MOZ_CrashSequence(__null, 439 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 440 | ||||
| 441 | n1.swap(n2); | |||
| 442 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 442); do { } while (false); do { MOZ_CrashSequence(__null, 442 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 443 | CHECK(n2.get() == p1)do { bool cond = !!(n2.get() == p1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 443); do { } while (false); do { MOZ_CrashSequence(__null, 443 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 444 | delete[] n2.release(); | |||
| 445 | ||||
| 446 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 446); do { } while (false); do { MOZ_CrashSequence(__null, 446 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 447 | CHECK(n2.get() == nullptr)do { bool cond = !!(n2.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 447); do { } while (false); do { MOZ_CrashSequence(__null, 447 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 448 | ||||
| 449 | int* p2 = new int[7]; | |||
| 450 | int* p3 = new int[42]; | |||
| 451 | n1.reset(p2); | |||
| 452 | n2.reset(p3); | |||
| 453 | CHECK(n1.get() == p2)do { bool cond = !!(n1.get() == p2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 453); do { } while (false); do { MOZ_CrashSequence(__null, 453 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 454 | CHECK(n2.get() == p3)do { bool cond = !!(n2.get() == p3); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 454); do { } while (false); do { MOZ_CrashSequence(__null, 454 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 455 | ||||
| 456 | n1.swap(n2); | |||
| 457 | CHECK(n2.get() == p2)do { bool cond = !!(n2.get() == p2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n2.get() == p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 457); do { } while (false); do { MOZ_CrashSequence(__null, 457 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 458 | CHECK(n1.get() == p3)do { bool cond = !!(n1.get() == p3); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == p3" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 458); do { } while (false); do { MOZ_CrashSequence(__null, 458 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 459 | ||||
| 460 | n1 = std::move(n2); | |||
| 461 | CHECK(n1.get() == p2)do { bool cond = !!(n1.get() == p2); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 461); do { } while (false); do { MOZ_CrashSequence(__null, 461 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 462 | n1 = std::move(n2); | |||
| 463 | CHECK(n1.get() == nullptr)do { bool cond = !!(n1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "n1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 463); do { } while (false); do { MOZ_CrashSequence(__null, 463 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 464 | ||||
| 465 | UniquePtr<A[]> a1(new A[17]); | |||
| 466 | static_assert(sizeof(a1) == sizeof(A*), "stored most efficiently"); | |||
| 467 | ||||
| 468 | UniquePtr<A[]> a2(new A[5], DefaultDelete<A[]>()); | |||
| 469 | a2.reset(nullptr); | |||
| 470 | a2.reset(new A[17]); | |||
| 471 | a2 = nullptr; | |||
| 472 | ||||
| 473 | UniquePtr<A[]> a3(nullptr); | |||
| 474 | a3.reset(new A[7]); | |||
| 475 | ||||
| 476 | return true; | |||
| 477 | } | |||
| 478 | ||||
| 479 | struct Q { | |||
| 480 | Q() = default; | |||
| 481 | Q(const Q&) = default; | |||
| 482 | ||||
| 483 | Q(Q&, char) {} | |||
| 484 | ||||
| 485 | template <typename T> | |||
| 486 | Q(Q, T&&, int) {} | |||
| 487 | ||||
| 488 | Q(int, long, double, void*) {} | |||
| 489 | }; | |||
| 490 | ||||
| 491 | static int randomInt() { return 4; } | |||
| 492 | ||||
| 493 | static bool TestMakeUnique() { | |||
| 494 | UniquePtr<int> a1(MakeUnique<int>()); | |||
| 495 | UniquePtr<long> a2(MakeUnique<long>(4)); | |||
| 496 | ||||
| 497 | // no args, easy | |||
| 498 | UniquePtr<Q> q0(MakeUnique<Q>()); | |||
| 499 | ||||
| 500 | // temporary bound to const lval ref | |||
| 501 | UniquePtr<Q> q1(MakeUnique<Q>(Q())); | |||
| 502 | ||||
| 503 | // passing through a non-const lval ref | |||
| 504 | UniquePtr<Q> q2(MakeUnique<Q>(*q1, 'c')); | |||
| 505 | ||||
| 506 | // pass by copying, forward a temporary, pass by value | |||
| 507 | UniquePtr<Q> q3(MakeUnique<Q>(Q(), UniquePtr<int>(), randomInt())); | |||
| 508 | ||||
| 509 | // various type mismatching to test "fuzzy" forwarding | |||
| 510 | UniquePtr<Q> q4(MakeUnique<Q>('s', 66LL, 3.141592654, &q3)); | |||
| 511 | ||||
| 512 | UniquePtr<char[]> c1(MakeUnique<char[]>(5)); | |||
| 513 | ||||
| 514 | return true; | |||
| 515 | } | |||
| 516 | ||||
| 517 | static bool TestVoid() { | |||
| 518 | // UniquePtr<void> supports all operations except operator*() and | |||
| 519 | // operator->(). | |||
| 520 | UniqueFreePtr<void> p1(malloc(1)); | |||
| 521 | UniqueFreePtr<void> p2; | |||
| 522 | ||||
| 523 | auto x = p1.get(); | |||
| 524 | CHECK(x != nullptr)do { bool cond = !!(x != nullptr); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "x != nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 524); do { } while (false); do { MOZ_CrashSequence(__null, 524 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 525 | CHECK((std::is_same_v<decltype(x), void*>))do { bool cond = !!((std::is_same_v<decltype(x), void*> )); do { static_assert( mozilla::detail::AssertionConditionType <decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "(std::is_same_v<decltype(x), void*>)" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 525); do { } while (false); do { MOZ_CrashSequence(__null, 525 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 526 | ||||
| 527 | p2.reset(p1.release()); | |||
| 528 | CHECK(p1.get() == nullptr)do { bool cond = !!(p1.get() == nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "p1.get() == nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 528); do { } while (false); do { MOZ_CrashSequence(__null, 528 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 529 | CHECK(p2.get() != nullptr)do { bool cond = !!(p2.get() != nullptr); do { static_assert( mozilla::detail::AssertionConditionType<decltype(cond)> ::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "p2.get() != nullptr" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 529); do { } while (false); do { MOZ_CrashSequence(__null, 529 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 530 | ||||
| 531 | p1 = std::move(p2); | |||
| 532 | CHECK(p1)do { bool cond = !!(p1); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 532); do { } while (false); do { MOZ_CrashSequence(__null, 532 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 533 | CHECK(!p2)do { bool cond = !!(!p2); do { static_assert( mozilla::detail ::AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "!p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 533); do { } while (false); do { MOZ_CrashSequence(__null, 533 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 534 | ||||
| 535 | p1.swap(p2); | |||
| 536 | CHECK(!p1)do { bool cond = !!(!p1); do { static_assert( mozilla::detail ::AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "!p1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 536); do { } while (false); do { MOZ_CrashSequence(__null, 536 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 537 | CHECK(p2)do { bool cond = !!(p2); do { static_assert( mozilla::detail:: AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 537); do { } while (false); do { MOZ_CrashSequence(__null, 537 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 538 | ||||
| 539 | p2 = nullptr; | |||
| 540 | CHECK(!p2)do { bool cond = !!(!p2); do { static_assert( mozilla::detail ::AssertionConditionType<decltype(cond)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("cond" " (" "Test failed: " "!p2" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 540); do { } while (false); do { MOZ_CrashSequence(__null, 540 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 541 | ||||
| 542 | return true; | |||
| 543 | } | |||
| 544 | ||||
| 545 | static bool TestTempPtrToSetter() { | |||
| 546 | static int sFooRefcount = 0; | |||
| 547 | struct Foo { | |||
| 548 | Foo() { sFooRefcount += 1; } | |||
| 549 | ||||
| 550 | ~Foo() { sFooRefcount -= 1; } | |||
| 551 | }; | |||
| 552 | ||||
| 553 | const auto AllocByOutvar = [](Foo** out) -> bool { | |||
| 554 | *out = new Foo; | |||
| 555 | return true; | |||
| 556 | }; | |||
| 557 | ||||
| 558 | { | |||
| 559 | UniquePtr<Foo> f; | |||
| 560 | (void)AllocByOutvar(mozilla::TempPtrToSetter(&f)); | |||
| 561 | CHECK(sFooRefcount == 1)do { bool cond = !!(sFooRefcount == 1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "sFooRefcount == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 561); do { } while (false); do { MOZ_CrashSequence(__null, 561 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 562 | } | |||
| 563 | CHECK(sFooRefcount == 0)do { bool cond = !!(sFooRefcount == 0); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "sFooRefcount == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 563); do { } while (false); do { MOZ_CrashSequence(__null, 563 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 564 | ||||
| 565 | { | |||
| 566 | std::unique_ptr<Foo> f; | |||
| 567 | (void)AllocByOutvar(mozilla::TempPtrToSetter(&f)); | |||
| 568 | CHECK(sFooRefcount == 1)do { bool cond = !!(sFooRefcount == 1); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "sFooRefcount == 1" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 568); do { } while (false); do { MOZ_CrashSequence(__null, 568 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 569 | } | |||
| 570 | CHECK(sFooRefcount == 0)do { bool cond = !!(sFooRefcount == 0); do { static_assert( mozilla ::detail::AssertionConditionType<decltype(cond)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(cond))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("cond" " (" "Test failed: " "sFooRefcount == 0" ")", "/root/firefox-clang/mfbt/tests/TestUniquePtr.cpp" , 570); do { } while (false); do { MOZ_CrashSequence(__null, 570 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); } while (false); | |||
| 571 | ||||
| 572 | return true; | |||
| 573 | } | |||
| 574 | ||||
| 575 | int main() { | |||
| 576 | TestDeleterType(); | |||
| 577 | ||||
| 578 | if (!TestDefaultFree()) { | |||
| 579 | return 1; | |||
| 580 | } | |||
| 581 | if (!TestFreeClass()) { | |||
| 582 | return 1; | |||
| 583 | } | |||
| 584 | if (!TestReferenceDeleter()) { | |||
| 585 | return 1; | |||
| 586 | } | |||
| 587 | if (!TestFunctionReferenceDeleter()) { | |||
| 588 | return 1; | |||
| 589 | } | |||
| 590 | if (!TestVector()) { | |||
| 591 | return 1; | |||
| 592 | } | |||
| 593 | if (!TestArray()) { | |||
| 594 | return 1; | |||
| 595 | } | |||
| 596 | if (!TestMakeUnique()) { | |||
| 597 | return 1; | |||
| 598 | } | |||
| 599 | if (!TestVoid()) { | |||
| 600 | return 1; | |||
| 601 | } | |||
| 602 | if (!TestTempPtrToSetter()) { | |||
| 603 | return 1; | |||
| 604 | } | |||
| 605 | return 0; | |||
| 606 | } |