Skip to content

Commit a812dcc

Browse files
committed
BREAKING CHANGE: Change contracts syntax to align with P2661R1
From `[[kind group: expression]]` to `kind<group>(expression)` Sorry for the breaking change to anyone who has been writing contacts. I'm trying to support gaining usage experience with P2961 Reference link: https://wg21.link/p2961r1
1 parent cdf71bd commit a812dcc

24 files changed

+113
-110
lines changed

regression-tests/mixed-bounds-safety-with-assert-2.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ main: () -> int = {
99

1010
add_42_to_subrange: (inout rng:_, start:int, end:int)
1111
= {
12-
[[assert Bounds: 0 <= start]]
13-
[[assert Bounds: end <= rng.ssize()]]
12+
assert<Bounds>( 0 <= start )
13+
assert<Bounds>( end <= rng.ssize() )
1414

1515
count := 0;
1616
for rng

regression-tests/mixed-bounds-safety-with-assert.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ main: () -> int = {
77
}
88

99
print_subrange: (rng:_, start:int, end:int) = {
10-
[[assert Bounds: 0 <= start]]
11-
[[assert Bounds: end <= rng.ssize()]]
10+
assert<Bounds>( 0 <= start )
11+
assert<Bounds>( end <= rng.ssize() )
1212

1313
count := 0;
1414
for rng
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <chrono>
22
using namespace std::chrono_literals;
33
main: () = {
4-
[[assert: 10 as i32 == 10]]
5-
[[assert: 10LL as i32 == 10]]
6-
[[assert: 10s as std::chrono::seconds == 10s]]
4+
assert( 10 as i32 == 10 )
5+
assert( 10LL as i32 == 10 )
6+
assert( 10s as std::chrono::seconds == 10s )
77
}

regression-tests/mixed-captures-in-expressions-and-postconditions.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ main: () -> int = {
1717
vec: std::vector<int> = ();
1818

1919
insert_at: (where: int, val: int)
20-
[[pre: 0 <= where && where <= vec.ssize()]]
21-
[[post: vec.ssize() == vec.ssize()$ + 1]]
20+
pre( 0 <= where && where <= vec.ssize() )
21+
post( vec.ssize() == vec.ssize()$ + 1 )
2222
= {
2323
_ = vec.insert( vec.begin()+where, val );
2424
}

regression-tests/mixed-initialization-safety-1-error.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ fill: (
1010
out x: std::string,
1111
in value: std::string,
1212
in count: int
13-
)
14-
[[pre: value.size() >= count, "fill: value must contain at least count elements"]]
13+
)
14+
pre( value.size() >= count, "fill: value must contain at least count elements" )
1515
= {
1616
x = value.substr(0, count);
1717
}

regression-tests/mixed-initialization-safety-2-error.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ fill: (
1010
out x: std::string,
1111
in value: std::string,
1212
in count: int
13-
)
14-
[[pre: value.size() >= count, "fill: value must contain at least count elements"]]
13+
)
14+
pre( value.size() >= count, "fill: value must contain at least count elements" )
1515
= {
1616
x = value.substr(0, count);
1717
}

regression-tests/mixed-initialization-safety-3-contract-violation.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fill: (
2020
value: std::string,
2121
count: int
2222
)
23-
[[pre: value.ssize() >= count, "fill: value must contain at least count elements"]]
23+
pre( value.ssize() >= count, "fill: value must contain at least count elements" )
2424
= {
2525
x = value.substr(0, count);
2626
}

regression-tests/mixed-initialization-safety-3.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fill: (
1818
value: std::string,
1919
count: int
2020
)
21-
[[pre: value.ssize() >= count, "fill: value must contain at least count elements"]]
21+
pre( value.ssize() >= count, "fill: value must contain at least count elements" )
2222
= {
2323
x = value.substr(0, count);
2424
}

regression-tests/mixed-postexpression-with-capture.cpp2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ main: () -> int = {
1111

1212
vec: std::vector<int> = ();
1313

14-
insert_at: (where: int, val: int)
15-
[[pre: 0 <= where && where <= vec.ssize()]]
16-
[[post: vec.size() == vec.size()$ + 1]]
14+
insert_at: (where: int, val: int)
15+
pre ( 0 <= where && where <= vec.ssize() )
16+
post( vec.size() == vec.size()$ + 1 )
1717
= {
1818
vec.push_back(val);
1919
}

regression-tests/pure2-bugfix-for-assign-expression-list.cpp2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ main: () = {
22
vec: type == std::vector<int>;
33
v: vec = (0);
44
v = ();
5-
[[assert: v == :vec = ()]]
5+
assert( v == :vec = () )
66
v = (1);
7-
[[assert: v == :vec = (1)]]
7+
assert( v == :vec = (1) )
88
v = (2, 3);
9-
[[assert: v == :vec = (2, 3)]]
9+
assert( v == :vec = (2, 3) )
1010
}

0 commit comments

Comments
 (0)