-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure valid type name for operators with multiple returns. (#796)
* Ensure valid type name for operators with multiple returns. * Added parent and bracket operator. * Added test * Tweak the implementation and run regressions * Use unused parameter to make tests compile cleanly --------- Co-authored-by: Ingo Prötel <[email protected]> Co-authored-by: Ingo Prötel <[email protected]> Co-authored-by: Herb Sutter <[email protected]>
- Loading branch information
1 parent
06f3173
commit 07e00c8
Showing
13 changed files
with
179 additions
and
20 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 |
---|---|---|
|
@@ -26,3 +26,4 @@ | |
*.bin | ||
*.exe | ||
source/gen_version.bat | ||
build*/ |
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,34 @@ | ||
|
||
A : type = { | ||
operator() : (this) -> (x: int, y: int) = { | ||
x = 12; | ||
y = 34; | ||
return; | ||
} | ||
operator* : (this) -> (x: int, y: int) = { | ||
x = 23; | ||
y = 45; | ||
return; | ||
} | ||
operator[] : (this, idx: int) -> (x: int, y: int) = { | ||
x = 34 * (idx+1); | ||
y = 56 * (idx+1); | ||
return; | ||
} | ||
} | ||
|
||
|
||
main : () = { | ||
|
||
a : A = (); | ||
|
||
t1 := a(); | ||
std::cout << t1.x << " , " << t1.y << "\n"; | ||
|
||
t2 := a*; | ||
std::cout << t2.x << " , " << t2.y << "\n"; | ||
|
||
t3 := a[0]; | ||
std::cout << t3.x << " , " << t3.y << "\n"; | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/clang-12/pure2-return-tuple-operator.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,3 @@ | ||
12 , 34 | ||
23 , 45 | ||
34 , 56 |
Empty file.
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/gcc-10/pure2-return-tuple-operator.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,3 @@ | ||
12 , 34 | ||
23 , 45 | ||
34 , 56 |
Empty file.
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/gcc-13/pure2-return-tuple-operator.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,3 @@ | ||
12 , 34 | ||
23 , 45 | ||
34 , 56 |
Empty file.
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/msvc-2022/pure2-return-tuple-operator.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,3 @@ | ||
12 , 34 | ||
23 , 45 | ||
34 , 56 |
1 change: 1 addition & 0 deletions
1
regression-tests/test-results/msvc-2022/pure2-return-tuple-operator.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-return-tuple-operator.cpp |
94 changes: 94 additions & 0 deletions
94
regression-tests/test-results/pure2-return-tuple-operator.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,94 @@ | ||
|
||
#define CPP2_IMPORT_STD Yes | ||
|
||
//=== Cpp2 type declarations ==================================================== | ||
|
||
|
||
#include "cpp2util.h" | ||
|
||
#line 1 "pure2-return-tuple-operator.cpp2" | ||
|
||
#line 2 "pure2-return-tuple-operator.cpp2" | ||
class A; | ||
|
||
|
||
//=== Cpp2 type definitions and function declarations =========================== | ||
|
||
#line 1 "pure2-return-tuple-operator.cpp2" | ||
|
||
#line 2 "pure2-return-tuple-operator.cpp2" | ||
class A { | ||
struct operator_call_ret { int x; int y; }; | ||
|
||
|
||
#line 3 "pure2-return-tuple-operator.cpp2" | ||
public: [[nodiscard]] auto operator()() const& -> operator_call_ret; | ||
struct operator_dereference_ret { int x; int y; }; | ||
|
||
|
||
|
||
#line 8 "pure2-return-tuple-operator.cpp2" | ||
public: [[nodiscard]] auto operator*() const& -> operator_dereference_ret; | ||
struct operator_subscript_ret { int x; int y; }; | ||
|
||
|
||
|
||
#line 13 "pure2-return-tuple-operator.cpp2" | ||
public: [[nodiscard]] auto operator[](cpp2::in<int> idx) const& -> operator_subscript_ret; | ||
public: A() = default; | ||
public: A(A const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(A const&) -> void = delete; | ||
|
||
|
||
#line 18 "pure2-return-tuple-operator.cpp2" | ||
}; | ||
|
||
#line 21 "pure2-return-tuple-operator.cpp2" | ||
auto main() -> int; | ||
|
||
//=== Cpp2 function definitions ================================================= | ||
|
||
#line 1 "pure2-return-tuple-operator.cpp2" | ||
|
||
#line 3 "pure2-return-tuple-operator.cpp2" | ||
[[nodiscard]] auto A::operator()() const& -> operator_call_ret{ | ||
cpp2::deferred_init<int> x; | ||
cpp2::deferred_init<int> y; | ||
#line 4 "pure2-return-tuple-operator.cpp2" | ||
x.construct(12); | ||
y.construct(34); | ||
return { std::move(x.value()), std::move(y.value()) }; | ||
} | ||
[[nodiscard]] auto A::operator*() const& -> operator_dereference_ret{ | ||
cpp2::deferred_init<int> x; | ||
cpp2::deferred_init<int> y; | ||
#line 9 "pure2-return-tuple-operator.cpp2" | ||
x.construct(23); | ||
y.construct(45); | ||
return { std::move(x.value()), std::move(y.value()) }; | ||
} | ||
[[nodiscard]] auto A::operator[](cpp2::in<int> idx) const& -> operator_subscript_ret{ | ||
cpp2::deferred_init<int> x; | ||
cpp2::deferred_init<int> y; | ||
#line 14 "pure2-return-tuple-operator.cpp2" | ||
x.construct(34 * (idx + 1)); | ||
y.construct(56 * (idx + 1)); | ||
return { std::move(x.value()), std::move(y.value()) }; | ||
} | ||
|
||
#line 21 "pure2-return-tuple-operator.cpp2" | ||
auto main() -> int{ | ||
|
||
A a {}; | ||
|
||
auto t1 {a()}; | ||
std::cout << t1.x << " , " << std::move(t1).y << "\n"; | ||
|
||
auto t2 {*cpp2::assert_not_null(a)}; | ||
std::cout << t2.x << " , " << std::move(t2).y << "\n"; | ||
|
||
auto t3 {CPP2_ASSERT_IN_BOUNDS(std::move(a), 0)}; | ||
std::cout << t3.x << " , " << std::move(t3).y << "\n"; | ||
|
||
} | ||
|
2 changes: 2 additions & 0 deletions
2
regression-tests/test-results/pure2-return-tuple-operator.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-return-tuple-operator.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