Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-53085

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

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

      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:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: