-
Notifications
You must be signed in to change notification settings - Fork 267
is(): correct is() for types #1204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hsutter
merged 14 commits into
hsutter:main
from
filipsajdak:fsajdak-extension-of-is-part2
Aug 10, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ce7fca6
Remove invalid check
filipsajdak c262c15
Remove dead code
filipsajdak f41e424
Remove extra parens
filipsajdak 6c3aed4
Fix formating
filipsajdak 5b1b3ad
Add test for is with polymorphic types
filipsajdak e1541c2
is(): add support for pointers
filipsajdak b9d0d2a
Update of tests to support is() with pointers
filipsajdak 5aa0354
is(): add support for nullptr_t
filipsajdak 11ac441
is(): add test for nullptr_t
filipsajdak b367b66
Add tests against unrelated type
filipsajdak 6d65bd9
is(): made is() compile-time when possible
filipsajdak 1d59c12
is(): fix test when is() returns std::bool_constant
filipsajdak 832a36f
Fix polymorphic tests
filipsajdak dbc388d
Remove empty .cpp.output files
filipsajdak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| A: type = {} | ||
|
|
||
| VA: @polymorphic_base <I:int> type = {} | ||
|
|
||
| VC: type = { | ||
| this: VA<0>; | ||
| this: VA<1>; | ||
| } | ||
|
|
||
| VD: type = { | ||
| this: VA<0>; | ||
| } | ||
|
|
||
| fun: (v, name) = { | ||
| std::cout << "(name)$ is"; | ||
| if v is VC { std::cout << " VC"; } | ||
| if v is VA<0> { std::cout << " VA<0>"; } | ||
| if v is VA<1> { std::cout << " VA<1>"; } | ||
| if v is VD { std::cout << " VD"; } | ||
| if v is *VC { std::cout << " *VC"; } | ||
| if v is *VA<0> { std::cout << " *VA<0>"; } | ||
| if v is *VA<1> { std::cout << " *VA<1>"; } | ||
| if v is *VD { std::cout << " *VD"; } | ||
| if v is void { std::cout << " empty"; } | ||
| if v is A { std::cout << " A"; } | ||
| std::cout << std::endl; | ||
| } | ||
|
|
||
| main: () = { | ||
|
|
||
| vc : VC = (); | ||
| p0 : *VA<0> = vc&; | ||
| p1 : *VA<1> = vc&; | ||
|
|
||
| fun(vc, "vc"); | ||
| fun(p0*, "p0*"); | ||
| fun(p1*, "p1*"); | ||
|
|
||
| fun(vc&, "vc&"); | ||
| fun(p0, "p0"); | ||
| fun(p1, "p1"); | ||
|
|
||
| fun(nullptr, "nullptr"); | ||
| fun(A(), "A"); | ||
| } |
8 changes: 8 additions & 0 deletions
8
...ion-tests/test-results/apple-clang-14-c++2b/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
...ion-tests/test-results/apple-clang-15-c++2b/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
regression-tests/test-results/clang-12-c++20/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
...on-tests/test-results/clang-15-c++20-libcpp/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
regression-tests/test-results/clang-15-c++20/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
regression-tests/test-results/clang-18-c++20/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
...on-tests/test-results/clang-18-c++23-libcpp/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
regression-tests/test-results/gcc-10-c++20/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
regression-tests/test-results/gcc-13-c++2b/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
regression-tests/test-results/gcc-14-c++2b/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
This file contains hidden or 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
8 changes: 8 additions & 0 deletions
8
regression-tests/test-results/msvc-2022-c++20/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
8 changes: 8 additions & 0 deletions
8
...sion-tests/test-results/msvc-2022-c++latest/pure2-is-with-polymorphic-types.cpp.execution
This file contains hidden or 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,8 @@ | ||
| vc is VC VA<0> VA<1> | ||
| p0* is VC VA<0> VA<1> | ||
| p1* is VC VA<0> VA<1> | ||
| vc& is *VC *VA<0> *VA<1> | ||
| p0 is *VC *VA<0> *VA<1> | ||
| p1 is *VC *VA<0> *VA<1> | ||
| nullptr is empty | ||
| A is A |
104 changes: 104 additions & 0 deletions
104
regression-tests/test-results/pure2-is-with-polymorphic-types.cpp
This file contains hidden or 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,104 @@ | ||
|
|
||
| #define CPP2_IMPORT_STD Yes | ||
|
|
||
| //=== Cpp2 type declarations ==================================================== | ||
|
|
||
|
|
||
| #include "cpp2util.h" | ||
|
|
||
| #line 1 "pure2-is-with-polymorphic-types.cpp2" | ||
| class A; | ||
| #line 2 "pure2-is-with-polymorphic-types.cpp2" | ||
|
|
||
| template<int I> class VA; | ||
|
|
||
| class VC; | ||
|
|
||
|
|
||
| #line 10 "pure2-is-with-polymorphic-types.cpp2" | ||
| class VD; | ||
|
|
||
|
|
||
| //=== Cpp2 type definitions and function declarations =========================== | ||
|
|
||
| #line 1 "pure2-is-with-polymorphic-types.cpp2" | ||
| class A { | ||
| public: A() = default; | ||
| public: A(A const&) = delete; /* No 'that' constructor, suppress copy */ | ||
| public: auto operator=(A const&) -> void = delete; | ||
| }; | ||
| #line 2 "pure2-is-with-polymorphic-types.cpp2" | ||
|
|
||
| template<int I> class VA { | ||
| public: virtual ~VA() noexcept; | ||
|
|
||
| public: VA() = default; | ||
| public: VA(VA const&) = delete; /* No 'that' constructor, suppress copy */ | ||
| public: auto operator=(VA const&) -> void = delete; | ||
| }; | ||
| #line 4 "pure2-is-with-polymorphic-types.cpp2" | ||
|
|
||
| class VC: public VA<0>, public VA<1> { | ||
| public: VC() = default; | ||
| public: VC(VC const&) = delete; /* No 'that' constructor, suppress copy */ | ||
| public: auto operator=(VC const&) -> void = delete; | ||
|
|
||
|
|
||
| #line 8 "pure2-is-with-polymorphic-types.cpp2" | ||
| }; | ||
|
|
||
| class VD: public VA<0> { | ||
| public: VD() = default; | ||
| public: VD(VD const&) = delete; /* No 'that' constructor, suppress copy */ | ||
| public: auto operator=(VD const&) -> void = delete; | ||
|
|
||
|
|
||
| #line 12 "pure2-is-with-polymorphic-types.cpp2" | ||
| }; | ||
|
|
||
| auto fun(auto const& v, auto const& name) -> void; | ||
|
|
||
| #line 29 "pure2-is-with-polymorphic-types.cpp2" | ||
| auto main() -> int; | ||
|
|
||
| //=== Cpp2 function definitions ================================================= | ||
|
|
||
| #line 1 "pure2-is-with-polymorphic-types.cpp2" | ||
|
|
||
|
|
||
| template <int I> VA<I>::~VA() noexcept{} | ||
| #line 14 "pure2-is-with-polymorphic-types.cpp2" | ||
| auto fun(auto const& v, auto const& name) -> void{ | ||
| std::cout << "" + cpp2::to_string(name) + " is"; | ||
| if (cpp2::impl::is<VC>(v)) {std::cout << " VC";} | ||
| if (cpp2::impl::is<VA<0>>(v)) {std::cout << " VA<0>";} | ||
| if (cpp2::impl::is<VA<1>>(v)) {std::cout << " VA<1>";} | ||
| if (cpp2::impl::is<VD>(v)) {std::cout << " VD";} | ||
| if (cpp2::impl::is<VC*>(v)) {std::cout << " *VC";} | ||
| if (cpp2::impl::is<VA<0>*>(v)) {std::cout << " *VA<0>";} | ||
| if (cpp2::impl::is<VA<1>*>(v)) {std::cout << " *VA<1>";} | ||
| if (cpp2::impl::is<VD*>(v)) {std::cout << " *VD";} | ||
| if (cpp2::impl::is<void>(v)) {std::cout << " empty";} | ||
| if (cpp2::impl::is<A>(v)) {std::cout << " A";} | ||
| std::cout << std::endl; | ||
| } | ||
|
|
||
| #line 29 "pure2-is-with-polymorphic-types.cpp2" | ||
| auto main() -> int{ | ||
|
|
||
| VC vc {}; | ||
| VA<0>* p0 {&vc}; | ||
| VA<1>* p1 {&vc}; | ||
|
|
||
| fun(vc, "vc"); | ||
| fun(*cpp2::impl::assert_not_null(p0), "p0*"); | ||
| fun(*cpp2::impl::assert_not_null(p1), "p1*"); | ||
|
|
||
| fun(&vc, "vc&"); | ||
| fun(cpp2::move(p0), "p0"); | ||
| fun(cpp2::move(p1), "p1"); | ||
|
|
||
| fun(nullptr, "nullptr"); | ||
| fun(A(), "A"); | ||
| } | ||
|
|
2 changes: 2 additions & 0 deletions
2
regression-tests/test-results/pure2-is-with-polymorphic-types.cpp2.output
This file contains hidden or 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-is-with-polymorphic-types.cpp2... ok (all Cpp2, passes safety checks) | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.