cppalliance / safe-cpp

Boost Software License 1.0
133 stars 12 forks source link

catch block arguments #56

Open cmazakas opened 4 weeks ago

cmazakas commented 4 weeks ago

In a catch block, if a thrown type has a non-trivial copy constructor, cpy isn't passively invoked for the user. See: https://godbolt.org/z/vfxPx5cWb

In the case of throwing a constructed object, the static constraint on references prevents this code from compiling as well: https://godbolt.org/z/T5o6TbWPz

seanbaxter commented 2 weeks ago
  1. Yes, need to specify how to support both cpy and other bindincs in the [safety] feature.
  2. An inaccurate error message but not a borrow checker bug. The exception object doesn't have static storage duration, so we can't bind static borrows to the exception object. I don't know what to do here. Maybe there needs to be a /throw lifetime? The exception object doesn't live on the stack, and it's not static... Is it sufficient to treat it as if it has automatic storage duration? I'd have to do some experiments to see if the __cxa_free_exception can occur prior to the closing brace of a catch-handler.