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