| 1 |
// general checks to ensure that contract violations are generated during |
| 2 |
// runtime when appropriate |
| 3 |
// each check also validates the expected file name, line number, function, |
| 4 |
// predicate, and contract level are included in the violation_info object |
| 5 |
// { dg-do run } |
| 6 |
// { dg-options "-std=c++2a -fcontracts -fcontract-build-level=audit -fcontract-continuation-mode=on" } |
| 7 |
|
| 8 |
namespace tns |
| 9 |
{ |
| 10 |
int fun() |
| 11 |
{ |
| 12 |
int x = 1; |
| 13 |
[[ assert: x < 0 ]]; |
| 14 |
return 0; |
| 15 |
} |
| 16 |
int fun2(); |
| 17 |
|
| 18 |
struct TestType |
| 19 |
{ |
| 20 |
static int fun(); |
| 21 |
static int fun2() |
| 22 |
{ |
| 23 |
int x = 1; |
| 24 |
[[ assert: x < 0 ]]; |
| 25 |
return 0; |
| 26 |
} |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
int tns::fun2() |
| 31 |
{ |
| 32 |
int x = 1; |
| 33 |
[[ assert: x < 0 ]]; |
| 34 |
return 0; |
| 35 |
} |
| 36 |
|
| 37 |
int tns::TestType::fun() |
| 38 |
{ |
| 39 |
int x = 1; |
| 40 |
[[ assert: x < 0 ]]; |
| 41 |
return 0; |
| 42 |
} |
| 43 |
|
| 44 |
int main() |
| 45 |
{ |
| 46 |
int x = 100; |
| 47 |
[[assert: x < 0]]; |
| 48 |
[[assert default: x < 1]]; |
| 49 |
[[assert audit: x < 2]]; |
| 50 |
// contract_violation.line_number() may eventually come from |
| 51 |
// std::source_location which *is* affected by the #line macro; our current |
| 52 |
// implementation conforms to this so we've included it as a check |
| 53 |
#line 100 |
| 54 |
[[assert: x < 3]]; |
| 55 |
[[assert axiom: x < 4]]; |
| 56 |
|
| 57 |
tns::fun(); |
| 58 |
tns::fun2(); |
| 59 |
|
| 60 |
tns::TestType::fun(); |
| 61 |
tns::TestType::fun2(); |
| 62 |
return 0; |
| 63 |
} |
| 64 |
|
| 65 |
// { dg-skip-if "requires hosted libstdc++ for stdc++exp" { ! hostedlib } } |
| 66 |
// { dg-output "contract violation in function main at .*.C:47: .*(\n|\r\n|\r)" } |
| 67 |
// { dg-output "contract violation in function main at .*.C:48: .*(\n|\r\n|\r)" } |
| 68 |
// { dg-output "contract violation in function main at .*.C:49: .*(\n|\r\n|\r)" } |
| 69 |
// { dg-output "contract violation in function main at .*.C:100: .*(\n|\r\n|\r)" } |
| 70 |
// { dg-output "contract violation in function tns::fun at .*.C:13: .*(\n|\r\n|\r)" } |
| 71 |
// { dg-output "contract violation in function tns::fun2 at .*.C:33: .*(\n|\r\n|\r)" } |
| 72 |
// { dg-output "contract violation in function tns::TestType::fun at .*.C:40: .*(\n|\r\n|\r)" } |
| 73 |
// { dg-output "contract violation in function tns::TestType::fun2 at .*.C:24: .*(\n|\r\n|\r)" } |
| 74 |
|