location_t);
/* in except.cc */
+extern void init_terminate_fn (void);
extern void init_exception_processing (void);
extern tree expand_start_catch_block (tree);
extern void expand_end_catch_block (void);
static bool is_admissible_throw_operand_or_catch_parameter (tree, bool,
tsubst_flags_t);
-/* Sets up all the global eh stuff that needs to be initialized at the
- start of compilation. */
+/* Initializes the node to std::terminate, which is used in exception
+ handling and contract handling. */
void
-init_exception_processing (void)
+init_terminate_fn (void)
{
+ if (terminate_fn)
+ return;
+
tree tmp;
- /* void std::terminate (); */
push_nested_namespace (std_node);
tmp = build_function_type_list (void_type_node, NULL_TREE);
terminate_fn = build_cp_library_fn_ptr ("terminate", tmp,
&& TREE_NOTHROW (terminate_fn));
pop_nested_namespace (std_node);
+}
+
+/* Sets up all the global eh stuff that needs to be initialized at the
+ start of compilation. */
+
+void
+init_exception_processing (void)
+{
+ tree tmp;
+
+ /* void std::terminate (); */
+ init_terminate_fn ();
+
/* void __cxa_call_unexpected(void *); */
tmp = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
call_unexpected_fn
--- /dev/null
+// check that contracts can be handled even when exceptions are disabled
+// { dg-do run }
+// { dg-options "-std=c++2a -fcontracts -fno-exceptions " }
+// { dg-output "contract violation in function f at .* a<5" }
+
+#include <exception>
+#include <cstdlib>
+
+int terminate_called = 0;
+void my_term()
+{
+ std::exit(0);
+}
+
+
+void f(int a)
+ [[ pre : a<5 ]]
+ {
+ }
+
+int
+main ()
+{
+ std::set_terminate (my_term);
+ f(3);
+ f(10);
+}