Skip to content

Commit 2c19edb

Browse files
committed
moar tests
1 parent 610b45b commit 2c19edb

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// generic error tests for generalized contract redecls
2+
// { dg-do compile }
3+
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontracts-nonattr-inheritance-mode=P2900R13" }
4+
5+
6+
struct Base
7+
{
8+
virtual int f(int a) pre (a > 0);
9+
};
10+
11+
struct Child : Base
12+
{
13+
int f(int a) pre (a < 0); // ok, does not inherit contracts
14+
};
15+
16+
struct F1
17+
{
18+
virtual int f(int a);
19+
};
20+
21+
int F1::f(int a) pre (a > 0) // { dg-error "declaration adds contracts" }
22+
{
23+
return -a;
24+
}
25+
26+
struct Foo {
27+
virtual void f10 (int) pre ( false ) {}
28+
};
29+
30+
struct Bar : Foo {
31+
void f10 (int n = 0) override pre ( false );
32+
};
33+
34+
// we currently don't diagnose an error here if the original contract was erroneous.
35+
void Bar::f10(int n) pre (n >10) {}; // { dg-error "mismatched contract" }
36+
37+
template <typename T>
38+
struct Base2
39+
{
40+
virtual int f(const int a) pre( a > 5 ) post( a > 7) { return a;};
41+
int g(const int a) pre( a > 5 ) post( a > 7) { return a;};
42+
virtual int h(int a) pre( a > 5 ) post( a > 7) { return a;}; // { dg-error "a value parameter used in a postcondition must be const" }
43+
int i(int a) pre( a > 5 ) post( a > 7) { return a;}; // { dg-error "a value parameter used in a postcondition must be const" }
44+
};
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// generic assert contract parsing checks
2+
// check omitted, 'default', 'audit', and 'axiom' contract levels parse
3+
// check that all concrete semantics parse
4+
// check omitted, '%default' contract roles parse
5+
// ensure that an invalid contract level 'invalid' errors
6+
// ensure that a predicate referencing an undefined variable errors
7+
// ensure that a missing colon after contract level errors
8+
// ensure that an invalid contract role 'invalid' errors
9+
// ensure that a missing colon after contract role errors
10+
// { dg-do compile }
11+
// { dg-options "-std=c++2a -fcontracts -fcontracts-nonattr -fcontracts-nonattr-inheritance-mode=P2900R13" }
12+
13+
struct B{
14+
15+
virtual void f() post(true) = 0;
16+
17+
};
18+
19+
struct D : B {
20+
void f() override post(true) = 0;
21+
};
22+
23+
// non attribute contracts come after override.
24+
struct E : D {
25+
void f() post(true) override; // { dg-error "expected" }
26+
// { dg-error "override" "" { target *-*-* } .-1 }
27+
};
28+
29+
30+
namespace other{
31+
32+
33+
struct X
34+
{
35+
virtual void f(int x) pre(x >= 0);
36+
};
37+
38+
struct Y : X
39+
{
40+
void f(int x) override pre(x >= 0);
41+
};
42+
43+
struct Y2 : X
44+
{
45+
void f(int x) pre(x >= 0) override; // { dg-error "expected .;. at end of member declaration|does not name a type" }
46+
};
47+
48+
struct Y3 : X
49+
{
50+
void f(int x) pre(x >= 0) override pre(x >= 0); // { dg-error "expected .;. at end of member declaration|does not name a type" }
51+
};
52+
53+
struct X2
54+
{
55+
virtual void f(int x) pre(x >= 0);
56+
};
57+
58+
struct X3
59+
{
60+
virtual void f(int x) final pre(x >= 0);
61+
};
62+
63+
struct X4
64+
{
65+
virtual void f(int x) pre(x >= 0) final; // { dg-error "expected .;. at end of member declaration|does not name a type" }
66+
};
67+
68+
struct X5
69+
{
70+
virtual void f(int x) pre(x >= 0) final pre(x >= 0); // { dg-error "expected .;. at end of member declaration|does not name a type" }
71+
};
72+
73+
74+
}
75+
76+
namespace parsing_virtual_test {
77+
struct A {
78+
virtual void f(int i)
79+
pre(i >= 0);
80+
};
81+
82+
struct B : A {
83+
void f(int i) override final
84+
pre(i >= 0);
85+
};
86+
87+
struct C : A {
88+
void f(int i) override
89+
pre(i >= 0) = 0;
90+
};
91+
}
92+
93+
namespace parsing_default_delete_pure_test {
94+
const bool a = true, b = true, c = true;
95+
96+
struct X {
97+
X() pre(a) = default;
98+
X(const X&) pre(b) = delete;
99+
virtual void f() pre(c) = 0;
100+
};
101+
}
102+
103+
int main()
104+
{
105+
}

0 commit comments

Comments
 (0)