Undefined behavior in ALL C++ unit test ASSERT statements (yes all)

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Internal Code
    • None
    • Service Arch
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      https://en.cppreference.com/w/cpp/memory/unique_ptr/~unique_ptr
      unique_ptr's dtor requires that the deleter must not throw. And yet, we're trying to use a unique_ptr to trigger a throw in unit tests, via the destructor ~TestAssertionFailure() noexcept(false).

      Well it doesn't matter if the object is marked noexcept(false) or not. An object with a throwing destructor CANNOT be destroyed by a unique_ptr going out of scope. It's UB.

      I think this means that any ASSERT failure in our test framework is UB.

      https://github.com/mongodb/mongo/blob/master/src/mongo/unittest/unittest.cpp#L598

      We can fix by just using something other than std::unique_ptr that doesn't have this restriction and is friendly to exception propagation out of destructors.

            Assignee:
            [DO NOT USE] Backlog - Service Architecture
            Reporter:
            Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: