On 7/5/21 3:07 PM, Jason Merrill wrote:
On 6/26/21 10:23 AM, Andrew Sutton wrote:
I ended up taking over this work from Jeff (CC'd on his existing email
address). I scraped all the contracts changes into one big patch
against master. See attached. The ChangeLog.contracts files list the
sum of changes for the patch, not the full history of the work.
Jonathan, can you advise where the library support should go?
In N4820 <contract> was part of the language-support clause, which makes
sense, but it uses string_view, which brings in a lot of the rest of the
library. Did LWG talk about this when contracts went in? How are
freestanding implementations expected to support contracts?
I imagine the header should be <experimental/contract> for now.
You've previously mentioned that various current experimental features
don't appear in libstdc++.so; that is not true of the current patch.
I see that https://github.com/arcosuc3m/clang-contracts takes the
approach, of teaching the compiler about std::contract_violation,
building up an object, and passing it to the handler directly, much like
we do for initializer_list. Their equivalent of __on_contract_violation
is an internal function emitted in each translation unit that needs it,
so it doesn't need to affect the library ABI. These both seem like
improvements to me.
More complicated is the question of the default violation handler: the
lock3 implementation calls it "handle_contract_violation" in the global
namespace, and overriding it is done with ELF symbol interposition, much
like the replaceable allocation functions. That approach seems
reasonable, but I'd think we should use a reserved name, e.g.
::__handle_contract_violation or __cxxabiv1::__contract_violation_handler.
The clang implementation above involves specifying the name of the
handler on the compiler command line, which seems problematic, as it
would tend to mean multiple independent violation handlers active at the
same time. Their default handler is std::terminate, which does avoid
needing to add the default handler to the library.
I've pushed the patch with my adjustments so far to devel/c++-contracts
on gcc.gnu.org. One of those adjustments was changing the
contract_violation data members to be const char *, to make creating an
object easier, and making the member functions inline, to reduce the
number of symbols added to the library.
Jason