Skip to content

Commit 7692d13

Browse files
Fix the violation handler noexcept work
The test needs to set an exception mask on cerr for streambuf exceptions to work. Also modify the noexceptness of the correct version of the violation handler, i.e. the nonattr one, not the legacy C++2a one.
1 parent f9979fc commit 7692d13

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

gcc/testsuite/g++.dg/contracts/cpp26/contract-violation-noexcept.C

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// test that the default contract violation handler can't throw
22
// { dg-do run }
3-
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on -fcontracts-nonattr " }
3+
// { dg-options "-std=c++2a -fcontracts -fcontract-evaluation-semantic=observe -fcontracts-nonattr " }
44

5-
#include <experimental/contract>
65
#include <iostream>
76
#include <exception>
87
#include <cstdlib>
@@ -75,14 +74,17 @@ public:
7574

7675
typedef fail_buf<std::streambuf> fail_streambuf;
7776

78-
7977
// Test that there is an active exception when we reach the terminate handler.
8078
void my_term()
8179
{
8280
try { throw; }
83-
catch(...) { std::exit(0); }
81+
catch(const underflow_error&) { std::exit(0); }
82+
catch(const overflow_error&) { std::exit(0); }
83+
catch(const positioning_error&) { std::exit(0); }
8484
}
8585

86+
87+
8688
void f(int x) pre(x >= 0)
8789
{
8890
try{
@@ -97,6 +99,7 @@ int main()
9799
std::set_terminate (my_term);
98100
fail_streambuf buf;
99101
std::cerr.rdbuf(&buf);
102+
std::cerr.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit);
100103
try
101104
{
102105
f(-42);

libstdc++-v3/src/experimental/contract.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#endif
3030

3131
__attribute__ ((weak)) void
32-
handle_contract_violation (const std::experimental::contract_violation &violation) noexcept
32+
handle_contract_violation (const std::experimental::contract_violation &violation)
3333
{
3434
#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
3535
bool level_default_p = violation.assertion_level() == "default";

libstdc++-v3/src/experimental/contract26.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#endif
3131

3232
__attribute__ ((weak)) void
33-
handle_contract_violation (const std::contracts::contract_violation &violation)
33+
handle_contract_violation (const std::contracts::contract_violation &violation) noexcept
3434
{
3535
#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
3636

0 commit comments

Comments
 (0)