File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < cassert>
2+
3+ void unused_param (int x) { (void )x; }
4+
5+ int side_effect_counter = 0 ;
6+ int bump_and_return () {
7+ ++side_effect_counter;
8+ return side_effect_counter;
9+ }
10+
11+ struct Holder {
12+ int field;
13+ };
14+
15+ int main () {
16+ unused_param (42 );
17+
18+ int y = 5 ;
19+ (void )y;
20+
21+ int z = ((void )y, 7 );
22+ assert (z == 7 );
23+
24+ int counter = 0 ;
25+ int w = ((void )counter, counter = 3 , counter);
26+ assert (w == 3 );
27+ assert (counter == 3 );
28+
29+ (void )bump_and_return ();
30+ assert (side_effect_counter == 1 );
31+
32+ int v = ((void )bump_and_return (), 99 );
33+ assert (side_effect_counter == 2 );
34+ assert (v == 99 );
35+
36+ (void )0 ;
37+ (void )(0 );
38+
39+ (void )(y);
40+
41+ ((void )0 );
42+ ((void )(y));
43+
44+ int err = 0 ;
45+ ((void )(err = 42 ));
46+ assert (err == 42 );
47+
48+ int chosen = ((void )(err = 7 ), 123 );
49+ assert (err == 7 );
50+ assert (chosen == 123 );
51+
52+ (void )bump_and_return;
53+ assert (side_effect_counter == 2 );
54+
55+ (void )(&bump_and_return);
56+ assert (side_effect_counter == 2 );
57+
58+ (void )(static_cast <int (*)()>(&bump_and_return));
59+ assert (side_effect_counter == 2 );
60+
61+ int storage = 11 ;
62+ int *p = &storage;
63+ (void )(*p);
64+
65+ int arr[] = {1 , 2 , 3 };
66+ (void )(arr[1 ]);
67+
68+ Holder h{17 };
69+ (void )(h.field );
70+ Holder *hp = &h;
71+ (void )(hp->field );
72+
73+ return 0 ;
74+ }
You can’t perform that action at this time.
0 commit comments