Debian Codegraph @

gcc/testsuite/g++.dg/contracts/contracts-ctor-dtor2.C

raw
1 // Tests to ensure that an invalid this parm cannot be used in pre on ctors or
2 // in post on dtors.
3 // { dg-do compile }
4 // { dg-options "-std=c++2a -fcontracts" }
5
6 struct F0
7 {
8 F0() [[ pre: x > 0 ]]; // { dg-error "invalid use of member" }
9 ~F0() [[ post: x > 0 ]]; // { dg-error "invalid use of member" }
10 int x{-1};
11 };
12
13 struct F1
14 {
15 F1() [[ pre: this->x > 0 ]]; // { dg-error "may not be used" }
16 ~F1() [[ post: this->x > 0 ]]; // { dg-error "may not be used" }
17 int x{-1};
18 };
19
20 struct F2
21 {
22 F2()
23 [[ post ret: false ]] // { dg-error "does not return a value" }
24 {
25 }
26 ~F2()
27 [[ post r: false ]] // { dg-error "does not return a value" }
28 {
29 }
30 void f()
31 [[ post r: false ]] // { dg-error "does not return a value" }
32 {
33 }
34 };
35