-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add chained comparisons, implements P0515R0 3.3 and P0893
Now `min < index <= max` work and do the right thing (in today's C++ they silently compile but are a bug, even if the programmer intended the meaningful chained comparison) And nonsense chains like `a >= b < c` are disallowed (in today's C++ they silently compile but are a bug, and conceptually meaningless)
- Loading branch information
Showing
16 changed files
with
309 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| main: () -> int = { | ||
| std::cout << std::boolalpha; | ||
| i:=0; while i<3 next i++ { | ||
| j:=0; while j<3 next j++ { | ||
| k:=0; while k<3 next k++ { | ||
| std::cout | ||
| << i << " " | ||
| << j << " " | ||
| << k << ": " | ||
| << (i == j == k) << " " | ||
| << (i < j <= k) << " " | ||
| << (i >= j > k) << "\n"; | ||
| } | ||
| } | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
regression-tests/test-results/clang-12/pure2-chained-comparisons.cpp.execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 0 0 0: true false false | ||
| 0 0 1: false false false | ||
| 0 0 2: false false false | ||
| 0 1 0: false false false | ||
| 0 1 1: false true false | ||
| 0 1 2: false true false | ||
| 0 2 0: false false false | ||
| 0 2 1: false false false | ||
| 0 2 2: false true false | ||
| 1 0 0: false false false | ||
| 1 0 1: false false false | ||
| 1 0 2: false false false | ||
| 1 1 0: false false true | ||
| 1 1 1: true false false | ||
| 1 1 2: false false false | ||
| 1 2 0: false false false | ||
| 1 2 1: false false false | ||
| 1 2 2: false true false | ||
| 2 0 0: false false false | ||
| 2 0 1: false false false | ||
| 2 0 2: false false false | ||
| 2 1 0: false false true | ||
| 2 1 1: false false false | ||
| 2 1 2: false false false | ||
| 2 2 0: false false true | ||
| 2 2 1: false false true | ||
| 2 2 2: true false false |
Empty file.
27 changes: 27 additions & 0 deletions
27
regression-tests/test-results/gcc-10/pure2-chained-comparisons.cpp.execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 0 0 0: true false false | ||
| 0 0 1: false false false | ||
| 0 0 2: false false false | ||
| 0 1 0: false false false | ||
| 0 1 1: false true false | ||
| 0 1 2: false true false | ||
| 0 2 0: false false false | ||
| 0 2 1: false false false | ||
| 0 2 2: false true false | ||
| 1 0 0: false false false | ||
| 1 0 1: false false false | ||
| 1 0 2: false false false | ||
| 1 1 0: false false true | ||
| 1 1 1: true false false | ||
| 1 1 2: false false false | ||
| 1 2 0: false false false | ||
| 1 2 1: false false false | ||
| 1 2 2: false true false | ||
| 2 0 0: false false false | ||
| 2 0 1: false false false | ||
| 2 0 2: false false false | ||
| 2 1 0: false false true | ||
| 2 1 1: false false false | ||
| 2 1 2: false false false | ||
| 2 2 0: false false true | ||
| 2 2 1: false false true | ||
| 2 2 2: true false false |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
regression-tests/test-results/msvc-2022/pure2-chained-comparisons.cpp.execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 0 0 0: true false false | ||
| 0 0 1: false false false | ||
| 0 0 2: false false false | ||
| 0 1 0: false false false | ||
| 0 1 1: false true false | ||
| 0 1 2: false true false | ||
| 0 2 0: false false false | ||
| 0 2 1: false false false | ||
| 0 2 2: false true false | ||
| 1 0 0: false false false | ||
| 1 0 1: false false false | ||
| 1 0 2: false false false | ||
| 1 1 0: false false true | ||
| 1 1 1: true false false | ||
| 1 1 2: false false false | ||
| 1 2 0: false false false | ||
| 1 2 1: false false false | ||
| 1 2 2: false true false | ||
| 2 0 0: false false false | ||
| 2 0 1: false false false | ||
| 2 0 2: false false false | ||
| 2 1 0: false false true | ||
| 2 1 1: false false false | ||
| 2 1 2: false false false | ||
| 2 2 0: false false true | ||
| 2 2 1: false false true | ||
| 2 2 2: true false false |
1 change: 1 addition & 0 deletions
1
regression-tests/test-results/msvc-2022/pure2-chained-comparisons.cpp.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pure2-chained-comparisons.cpp |
28 changes: 28 additions & 0 deletions
28
regression-tests/test-results/pure2-chained-comparisons.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // ----- Cpp2 support ----- | ||
| #define CPP2_USE_MODULES Yes | ||
| #include "cpp2util.h" | ||
|
|
||
|
|
||
| #line 1 "pure2-chained-comparisons.cpp2" | ||
| [[nodiscard]] auto main() -> int; | ||
|
|
||
| //=== Cpp2 definitions ========================================================== | ||
|
|
||
| #line 1 "pure2-chained-comparisons.cpp2" | ||
| [[nodiscard]] auto main() -> int{ | ||
| std::cout << std::boolalpha; | ||
| auto i {0}; for( ; cpp2::cmp_less(i,3); ++i ) { | ||
| auto j {0}; for( ; cpp2::cmp_less(j,3); ++j ) { | ||
| auto k {0}; for( ; cpp2::cmp_less(k,3); ++k ) { | ||
| std::cout | ||
| << i << " " | ||
| << j << " " | ||
| << k << ": " | ||
| << ([_0 = i, _1 = j, _2 = k]{ return _0==_1 && _1==_2; }()) << " " | ||
| << ([_0 = i, _1 = j, _2 = k]{ return cpp2::cmp_less(_0,_1) && cpp2::cmp_less_eq(_1,_2); }()) << " " | ||
| << ([_0 = i, _1 = j, _2 = k]{ return cpp2::cmp_greater_eq(_0,_1) && cpp2::cmp_greater(_1,_2); }()) << "\n"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
2 changes: 2 additions & 0 deletions
2
regression-tests/test-results/pure2-chained-comparisons.cpp2.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| pure2-chained-comparisons.cpp2... ok (all Cpp2, passes safety checks) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.