cppalliance / safe-cpp

Boost Software License 1.0
191 stars 14 forks source link

drop_only tests for all containers #34

Closed seanbaxter closed 2 months ago

seanbaxter commented 2 months ago

I ran into borrowck errors with vector and box because they didn't have drop_only on the dtor. As an example how to raise this:

#feature on safety
#include <std2.h>

using namespace std2;

int main() safe {
  // The box is declared before the string.
  box<string_view> b;

  // The string will be destroyed before the box.
  string s = "From string object 1";

  // Initialize a box with a view into the string.
  b = box<string_view>(s);

  // string destroyed.
  // box destroyed. Without drop_only it uses the template lifetime 
  // parameter which borrows on s. That's a borrow checker error.
}

Need to make sure all container-like classes implement drop_only on their dtors.

cmazakas commented 2 months ago

This should be all good to go now with: https://github.com/cppalliance/safe-cpp/commit/7c9de070e8f9b1c47d62c185a2fa6752f86b9282 https://github.com/cppalliance/safe-cpp/commit/a15245abbd5171723b830180884d0b7b8830f703 https://github.com/cppalliance/safe-cpp/commit/2fd4fb2272cb432f43c726d98354db593d7dd20d

Closing for now