Skip to content

Commit 253cc7f

Browse files
villevoutilaineniains
authored andcommitted
Add a missing case for NOEXCEPT_ENFORCE
1 parent 4b6b810 commit 253cc7f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

gcc/cp/contracts.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ build_contract_check (tree contract)
23902390
finish_expr_stmt (finish_call_expr (fn, &vec, false, false,
23912391
tf_warning_or_error));
23922392
}
2393-
else if (semantic == CCS_ENFORCE)
2393+
else if (semantic == CCS_ENFORCE || semantic == CCS_NOEXCEPT_ENFORCE)
23942394
/* FIXME: we should not call this when exceptions are disabled. */
23952395
finish_expr_stmt (build_call_a (terminate_fn, 0, nullptr));
23962396
finish_then_clause (if_stmt);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// { dg-do run }
2+
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=noexcept_enforce " }
3+
#include <experimental/contract>
4+
#include <exception>
5+
#include <cstdlib>
6+
7+
// Test that there is an active exception when we reach the terminate handler.
8+
void my_term()
9+
{
10+
std::exit(0);
11+
}
12+
13+
void handle_contract_violation(const std::experimental::contract_violation& violation)
14+
{
15+
}
16+
17+
void f(int x) pre(x >= 0)
18+
{
19+
}
20+
21+
int main()
22+
{
23+
std::set_terminate (my_term);
24+
f(-42);
25+
// We should not get here
26+
return 1;
27+
}

0 commit comments

Comments
 (0)