File tree Expand file tree Collapse file tree 2 files changed +74
-2
lines changed
libstdc++-v3/testsuite/18_support/contracts Expand file tree Collapse file tree 2 files changed +74
-2
lines changed Original file line number Diff line number Diff line change 21
21
#include < contracts>
22
22
#include < testsuite_hooks.h>
23
23
24
- bool custom_called = 1 ;
24
+ bool custom_called = false ;
25
25
26
26
27
27
void handle_contract_violation (const std::contracts::contract_violation& v)
28
28
{
29
29
invoke_default_contract_violation_handler (v);
30
+ custom_called = true ;
30
31
}
31
32
32
33
void f (int i) pre (i>10 ) {};
33
34
34
35
int main ()
35
36
{
36
37
f (0 );
37
- VERIFY (custom_called == 1 );
38
+ VERIFY (custom_called);
38
39
}
39
40
// { dg-output "contract violation in function f at .*(\n|\r\n|\r)" }
Original file line number Diff line number Diff line change
1
+ // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2
+ //
3
+ // This file is part of the GNU ISO C++ Library. This library is free
4
+ // software; you can redistribute it and/or modify it under the
5
+ // terms of the GNU General Public License as published by the
6
+ // Free Software Foundation; either version 3, or (at your option)
7
+ // any later version.
8
+
9
+ // This library is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ // GNU General Public License for more details.
13
+
14
+ // You should have received a copy of the GNU General Public License along
15
+ // with this library; see the file COPYING3. If not see
16
+ // <http://www.gnu.org/licenses/>.
17
+
18
+ // { dg-options "-g0 -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=observe" }
19
+ // { dg-do run { target c++2a } }
20
+
21
+ #include < contracts>
22
+ #include < testsuite_hooks.h>
23
+ #include < iostream>
24
+ #include < sstream>
25
+
26
+
27
+ struct checking_buf
28
+ : public std::streambuf
29
+ {
30
+ bool written = false ;
31
+
32
+ checking_buf () = default ;
33
+
34
+ virtual int_type
35
+ overflow (int_type)
36
+ {
37
+ written = true ;
38
+ return int_type ();
39
+ }
40
+
41
+ std::streamsize xsputn (const char * s, std::streamsize count)
42
+ {
43
+ written = true ;
44
+ return count;
45
+ }
46
+
47
+ };
48
+
49
+
50
+ bool custom_called = false ;
51
+
52
+
53
+ void handle_contract_violation (const std::contracts::contract_violation& v)
54
+ {
55
+ custom_called = true ;
56
+ }
57
+
58
+
59
+
60
+
61
+ void f (int i) pre (i>10 ) {};
62
+
63
+ int main ()
64
+ {
65
+ checking_buf buf;
66
+ std::cerr.rdbuf (&buf);
67
+
68
+ f (0 );
69
+ VERIFY (!buf.written );
70
+ }
71
+
You can’t perform that action at this time.
0 commit comments