| 1 |
// Tests to ensure that contracts are properly emitted for constructors, |
| 2 |
// destructors, and their intersection with templates. |
| 3 |
// { dg-do compile } |
| 4 |
// { dg-options "-std=c++2a -fcontracts" } |
| 5 |
|
| 6 |
bool pre_{false}, post_{false}; |
| 7 |
bool delegate_{false}; |
| 8 |
|
| 9 |
struct S |
| 10 |
{ |
| 11 |
S() [[ pre: pre_ ]] [[ post: post_ ]]; |
| 12 |
~S() [[ pre: pre_ ]] [[ post: post_ ]]; |
| 13 |
}; |
| 14 |
|
| 15 |
S::S() { return; } |
| 16 |
S::~S() { return; } |
| 17 |
|
| 18 |
struct SInline |
| 19 |
{ |
| 20 |
SInline() [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 21 |
~SInline() [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 22 |
}; |
| 23 |
|
| 24 |
struct SDelegate0 |
| 25 |
{ |
| 26 |
SDelegate0(int) [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 27 |
SDelegate0() : SDelegate0(0) { return; } |
| 28 |
~SDelegate0() [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 29 |
}; |
| 30 |
|
| 31 |
struct SDelegate1 |
| 32 |
{ |
| 33 |
SDelegate1(int) { return; } |
| 34 |
SDelegate1() [[ pre: pre_ ]] [[ post: post_ ]] : SDelegate1(0) { return; } |
| 35 |
~SDelegate1() [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 36 |
}; |
| 37 |
|
| 38 |
struct SDelegate2 |
| 39 |
{ |
| 40 |
SDelegate2(int) [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 41 |
SDelegate2() [[ pre: pre_ && delegate_ ]] [[ post: post_ && delegate_ ]] : SDelegate2(0) { return; } |
| 42 |
~SDelegate2() [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 43 |
}; |
| 44 |
|
| 45 |
struct SDelegate3 |
| 46 |
{ |
| 47 |
SDelegate3(int) [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 48 |
SDelegate3() [[ pre: pre_ && delegate_ ]] [[ post: post_ && delegate_ ]] : SDelegate3(0) { return; } |
| 49 |
~SDelegate3() [[ pre: pre_ ]] [[ post: post_ ]] { return; } |
| 50 |
}; |
| 51 |
|
| 52 |
template<typename T> |
| 53 |
struct S1 |
| 54 |
{ |
| 55 |
S1() [[ pre: pre_ ]] [[ post: post_ ]] { } |
| 56 |
}; |
| 57 |
|
| 58 |
struct S2 |
| 59 |
{ |
| 60 |
template<typename T> |
| 61 |
S2(T) [[ pre: pre_ ]] [[ post: post_ ]] { } |
| 62 |
}; |
| 63 |
|
| 64 |
template<typename T> |
| 65 |
struct S3 |
| 66 |
{ |
| 67 |
template<typename S> |
| 68 |
S3(S) [[ pre: pre_ ]] [[ post: post_ ]] { } |
| 69 |
}; |
| 70 |
|
| 71 |
struct G0 |
| 72 |
{ |
| 73 |
G0() [[ post: x > 0 ]] {} |
| 74 |
~G0() [[ pre: x > 0 ]] {} |
| 75 |
int x{-1}; |
| 76 |
}; |
| 77 |
|
| 78 |
struct G1 |
| 79 |
{ |
| 80 |
G1() [[ post: this->x > 0 ]] {} |
| 81 |
~G1() [[ pre: this->x > 0 ]] {} |
| 82 |
int x{-1}; |
| 83 |
}; |
| 84 |
|
| 85 |
int x{-1}; |
| 86 |
|
| 87 |
struct G2 |
| 88 |
{ |
| 89 |
G2() [[ pre: ::x > 0 ]] {} |
| 90 |
~G2() [[ post: ::x > 0 ]] {} |
| 91 |
int x{1}; |
| 92 |
}; |
| 93 |
|
| 94 |
void test0() |
| 95 |
{ |
| 96 |
S s; |
| 97 |
SInline si; |
| 98 |
SDelegate0 sd0; |
| 99 |
SDelegate1 sd1; |
| 100 |
SDelegate2 sd2; |
| 101 |
SDelegate3 sd3; |
| 102 |
S1<int> s1_i; |
| 103 |
S1<double> s1_d; |
| 104 |
S2 s2_i{1}; |
| 105 |
S2 s2_d{.1}; |
| 106 |
S3<int> s3_i_i{1}; |
| 107 |
S3<int> s3_i_d{.1}; |
| 108 |
S3<double> s3_d_i{1}; |
| 109 |
S3<double> s3_d_d{.1}; |
| 110 |
} |
| 111 |
|
| 112 |
void test1() |
| 113 |
{ |
| 114 |
G0 g0; |
| 115 |
G1 g1; |
| 116 |
G2 g2; |
| 117 |
} |
| 118 |
|
| 119 |
int main(int, char**) |
| 120 |
{ |
| 121 |
test0(); |
| 122 |
test1(); |
| 123 |
return 0; |
| 124 |
}; |
| 125 |
|
| 126 |
// test0 |
| 127 |
// { dg-output "contract violation in function S::S at .*.C:11 .*(\n|\r\n|\r)" } |
| 128 |
// { dg-output "contract violation in function S::S at .*.C:11 .*(\n|\r\n|\r)" } |
| 129 |
// { dg-output "contract violation in function SInline::SInline at .*.C:20 .*(\n|\r\n|\r)" } |
| 130 |
// { dg-output "contract violation in function SInline::SInline at .*.C:20 .*(\n|\r\n|\r)" } |
| 131 |
// { dg-output "contract violation in function SDelegate0::SDelegate0 at .*.C:26 .*(\n|\r\n|\r)" } |
| 132 |
// { dg-output "contract violation in function SDelegate0::SDelegate0 at .*.C:26 .*(\n|\r\n|\r)" } |
| 133 |
// { dg-output "contract violation in function SDelegate1::SDelegate1 at .*.C:34 .*(\n|\r\n|\r)" } |
| 134 |
// { dg-output "contract violation in function SDelegate1::SDelegate1 at .*.C:34 .*(\n|\r\n|\r)" } |
| 135 |
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:41 .*(\n|\r\n|\r)" } |
| 136 |
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:40 .*(\n|\r\n|\r)" } |
| 137 |
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:40 .*(\n|\r\n|\r)" } |
| 138 |
// { dg-output "contract violation in function SDelegate2::SDelegate2 at .*.C:41 .*(\n|\r\n|\r)" } |
| 139 |
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:48 .*(\n|\r\n|\r)" } |
| 140 |
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:47 .*(\n|\r\n|\r)" } |
| 141 |
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:47 .*(\n|\r\n|\r)" } |
| 142 |
// { dg-output "contract violation in function SDelegate3::SDelegate3 at .*.C:48 .*(\n|\r\n|\r)" } |
| 143 |
// { dg-output "contract violation in function S1<int>::S1 at .*.C:55 .*(\n|\r\n|\r)" } |
| 144 |
// { dg-output "contract violation in function S1<int>::S1 at .*.C:55 .*(\n|\r\n|\r)" } |
| 145 |
// { dg-output "contract violation in function S1<double>::S1 at .*.C:55 .*(\n|\r\n|\r)" } |
| 146 |
// { dg-output "contract violation in function S1<double>::S1 at .*.C:55 .*(\n|\r\n|\r)" } |
| 147 |
// { dg-output "contract violation in function S2::S2<int> at .*.C:61 .*(\n|\r\n|\r)" } |
| 148 |
// { dg-output "contract violation in function S2::S2<int> at .*.C:61 .*(\n|\r\n|\r)" } |
| 149 |
// { dg-output "contract violation in function S2::S2<double> at .*.C:61 .*(\n|\r\n|\r)" } |
| 150 |
// { dg-output "contract violation in function S2::S2<double> at .*.C:61 .*(\n|\r\n|\r)" } |
| 151 |
// { dg-output "contract violation in function S3<int>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" } |
| 152 |
// { dg-output "contract violation in function S3<int>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" } |
| 153 |
// { dg-output "contract violation in function S3<int>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" } |
| 154 |
// { dg-output "contract violation in function S3<int>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" } |
| 155 |
// { dg-output "contract violation in function S3<double>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" } |
| 156 |
// { dg-output "contract violation in function S3<double>::S3<int> at .*.C:68 .*(\n|\r\n|\r)" } |
| 157 |
// { dg-output "contract violation in function S3<double>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" } |
| 158 |
// { dg-output "contract violation in function S3<double>::S3<double> at .*.C:68 .*(\n|\r\n|\r)" } |
| 159 |
// { dg-output "contract violation in function SDelegate3::~SDelegate3 at .*.C:49 .*(\n|\r\n|\r)" } |
| 160 |
// { dg-output "contract violation in function SDelegate3::~SDelegate3 at .*.C:49 .*(\n|\r\n|\r)" } |
| 161 |
// { dg-output "contract violation in function SDelegate2::~SDelegate2 at .*.C:42 .*(\n|\r\n|\r)" } |
| 162 |
// { dg-output "contract violation in function SDelegate2::~SDelegate2 at .*.C:42 .*(\n|\r\n|\r)" } |
| 163 |
// { dg-output "contract violation in function SDelegate1::~SDelegate1 at .*.C:35 .*(\n|\r\n|\r)" } |
| 164 |
// { dg-output "contract violation in function SDelegate1::~SDelegate1 at .*.C:35 .*(\n|\r\n|\r)" } |
| 165 |
// { dg-output "contract violation in function SDelegate0::~SDelegate0 at .*.C:28 .*(\n|\r\n|\r)" } |
| 166 |
// { dg-output "contract violation in function SDelegate0::~SDelegate0 at .*.C:28 .*(\n|\r\n|\r)" } |
| 167 |
// { dg-output "contract violation in function SInline::~SInline at .*.C:21 .*(\n|\r\n|\r)" } |
| 168 |
// { dg-output "contract violation in function SInline::~SInline at .*.C:21 .*(\n|\r\n|\r)" } |
| 169 |
// { dg-output "contract violation in function S::~S at .*.C:12 .*(\n|\r\n|\r)" } |
| 170 |
// { dg-output "contract violation in function S::~S at .*.C:12 .*(\n|\r\n|\r)" } |
| 171 |
|
| 172 |
// test1 |
| 173 |
// { dg-output "contract violation in function G0::G0 at .*.C:73 .*(\n|\r\n|\r)" } |
| 174 |
// { dg-output "contract violation in function G1::G1 at .*.C:80 .*(\n|\r\n|\r)" } |
| 175 |
// { dg-output "contract violation in function G1::~G1 at .*.C:81 .*(\n|\r\n|\r)" } |
| 176 |
// { dg-output "contract violation in function G0::~G0 at .*.C:74 .*(\n|\r\n|\r)" } |
| 177 |
|