-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The syntax is `specialize<specialization_arguments>` after the optional template parameter list. Some examples from the tests: ```Cpp2 std: namespace = { common_type: @struct @print specialize<outer, outer> type = { type: type == outer; } } v: <T> const i32 = 1; v: <> specialize<void> const i32 = 2; v: specialize<i64> const i32 = 3; v: <T> specialize<* T> std::optional<int> == 6; ```
- Loading branch information
Showing
22 changed files
with
357 additions
and
31 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 @@ | ||
a1: <T> namespace == { } |
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 @@ | ||
a2: namespace requires true == { } |
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 @@ | ||
a3: type requires true = { } |
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 @@ | ||
a4: specialize<> type == int; |
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 @@ | ||
a5: specialize<> namespace == std; |
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 @@ | ||
n1: <T> namespace = { } |
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 @@ | ||
n2: namespace requires true = { } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
t: @cpp1_rule_of_zero <T> type = { | ||
public a: i32 = 1; | ||
} | ||
t: @cpp1_rule_of_zero <T> specialize<T> type requires std::is_void_v<T> = { | ||
public b: i32 = 2; | ||
} | ||
t: @cpp1_rule_of_zero specialize<i64> type = { | ||
public c: i32 = 3; | ||
} | ||
t: @cpp1_rule_of_zero specialize<* i8> type = { | ||
public f: () = 17; | ||
public v: int == 29; | ||
} | ||
t: @cpp1_rule_of_zero <T> specialize<* T> type = { | ||
public v: int == 17; | ||
public f: () = 29; | ||
} | ||
u: @cpp1_rule_of_zero <T...> type = { | ||
public a: i32 = 1; | ||
} | ||
u: @cpp1_rule_of_zero specialize<> type = { | ||
public a: i32 = 2; | ||
} | ||
u: specialize<i16> type = { } | ||
v: <T> const i32 = 1; | ||
v: <> specialize<void> const i32 = 2; | ||
v: specialize<i64> const i32 = 3; | ||
v: specialize<i16> std::optional<i32> == 4; | ||
v: <> specialize<i8> std::optional<i8> == 5; | ||
v: <T> specialize<* T> std::optional<int> == 6; | ||
main: () = { | ||
assert(t<i32>().a == 1); | ||
assert(t<void>().b == 2); | ||
assert(t<i64>().c == 3); | ||
assert(t<* i8>::f() == 17); | ||
assert(t<* i8>::v == 29); | ||
assert(t<* i16>::v == 17); | ||
assert(t<* i16>::f() == 29); | ||
assert(u<i32>().a == 1); | ||
assert(u<>().a == 1); | ||
assert(v<i32> == 1); | ||
assert(v<void> == 2); | ||
assert(v<i64> == 3); | ||
static_assert(v<i16> == 4); | ||
static_assert(v<i8> == 5); | ||
static_assert(v<* int> == 6); | ||
} |
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/pure2-alias-1-error.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,3 @@ | ||
pure2-alias-1-error.cpp2... | ||
pure2-alias-1-error.cpp2(1,19): error: a namespace or namespace alias cannot have template parameters | ||
|
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/pure2-alias-2-error.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,3 @@ | ||
pure2-alias-2-error.cpp2... | ||
pure2-alias-2-error.cpp2(1,15): error: 'requires' is not allowed on a namespace alias (at 'requires') | ||
|
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/pure2-alias-3-error.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,3 @@ | ||
pure2-alias-3-error.cpp2... | ||
pure2-alias-3-error.cpp2(1,10): error: 'requires' is not allowed on a type alias that does not have a template parameter list (at 'requires') | ||
|
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/pure2-alias-4-error.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,3 @@ | ||
pure2-alias-4-error.cpp2... | ||
pure2-alias-4-error.cpp2(1,18): error: a type alias cannot be specialized | ||
|
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/pure2-alias-5-error.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,3 @@ | ||
pure2-alias-5-error.cpp2... | ||
pure2-alias-5-error.cpp2(1,18): error: a namespace alias cannot be specialized | ||
|
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/pure2-namespace-1-error.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,3 @@ | ||
pure2-namespace-1-error.cpp2... | ||
pure2-namespace-1-error.cpp2(1,19): error: a namespace or namespace alias cannot have template parameters | ||
|
3 changes: 3 additions & 0 deletions
3
regression-tests/test-results/pure2-namespace-2-error.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,3 @@ | ||
pure2-namespace-2-error.cpp2... | ||
pure2-namespace-2-error.cpp2(1,15): error: 'requires' is not allowed on a namespace alias (at 'requires') | ||
|
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
94 changes: 94 additions & 0 deletions
94
regression-tests/test-results/pure2-template-specialization.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-template-specialization.cpp2" | ||
template<typename T> class t; | ||
#line 2 "pure2-template-specialization.cpp2" | ||
|
||
|
||
#line 18 "pure2-template-specialization.cpp2" | ||
template<typename ...T> class u; | ||
|
||
|
||
//=== Cpp2 type definitions and function declarations =========================== | ||
|
||
#line 1 "pure2-template-specialization.cpp2" | ||
template<typename T> class t { | ||
#line 2 "pure2-template-specialization.cpp2" | ||
public: cpp2::i32 a {1}; | ||
}; | ||
template<typename T> requires( std::is_void_v<T> ) | ||
class t<T> {public: cpp2::i32 b {2}; | ||
}; | ||
template<> class t<cpp2::i64> { | ||
public: cpp2::i32 c {3}; | ||
}; | ||
template<> class t<cpp2::i8*> { | ||
public: [[nodiscard]] static auto f() -> decltype(auto); | ||
public: static const int v; | ||
}; | ||
template<typename T> class t<T*> { | ||
public: static const int v; | ||
public: [[nodiscard]] static auto f() -> decltype(auto); | ||
}; | ||
template<typename ...T> class u { | ||
public: cpp2::i32 a {1}; | ||
}; | ||
template<> class u<> { | ||
public: cpp2::i32 a {2}; | ||
}; | ||
template<> class u<cpp2::i16> { | ||
public: u() = default; | ||
public: u(u const&) = delete; /* No 'that' constructor, suppress copy */ | ||
public: auto operator=(u const&) -> void = delete; | ||
}; | ||
#line 25 "pure2-template-specialization.cpp2" | ||
template<typename T> extern cpp2::i32 const v; | ||
|
||
#line 28 "pure2-template-specialization.cpp2" | ||
template<> std::optional<cpp2::i32> inline constexpr v<cpp2::i16>{ 4 }; | ||
template<> std::optional<cpp2::i8> inline constexpr v<cpp2::i8>{ 5 }; | ||
template<typename T> std::optional<int> inline constexpr v<T*>{ 6 }; | ||
auto main() -> int; | ||
|
||
//=== Cpp2 function definitions ================================================= | ||
|
||
#line 1 "pure2-template-specialization.cpp2" | ||
|
||
#line 11 "pure2-template-specialization.cpp2" | ||
[[nodiscard]] auto t<cpp2::i8*>::f() -> decltype(auto) { return 17; } | ||
inline CPP2_CONSTEXPR int t<cpp2::i8*>::v{ 29 }; | ||
|
||
#line 15 "pure2-template-specialization.cpp2" | ||
template <typename T> inline CPP2_CONSTEXPR int t<T*>::v{ 17 }; | ||
template <typename T> [[nodiscard]] auto t<T*>::f() -> decltype(auto) { return 29; } | ||
|
||
#line 25 "pure2-template-specialization.cpp2" | ||
template<typename T> cpp2::i32 const v {1}; | ||
template<> cpp2::i32 const v<void> {2}; | ||
template<> cpp2::i32 const v<cpp2::i64> {3}; | ||
|
||
#line 31 "pure2-template-specialization.cpp2" | ||
auto main() -> int{ | ||
if (cpp2::cpp2_default.is_active() && !(t<cpp2::i32>().a == 1) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(t<void>().b == 2) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(t<cpp2::i64>().c == 3) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(t<cpp2::i8*>::f() == 17) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(t<cpp2::i8*>::v == 29) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(t<cpp2::i16*>::v == 17) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(t<cpp2::i16*>::f() == 29) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(u<cpp2::i32>().a == 1) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(u<>().a == 1) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(v<cpp2::i32> == 1) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(v<void> == 2) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(v<cpp2::i64> == 3) ) { cpp2::cpp2_default.report_violation(""); } | ||
static_assert(v<cpp2::i16> == 4); | ||
static_assert(v<cpp2::i8> == 5); | ||
static_assert(v<int*> == 6); | ||
} | ||
|
2 changes: 2 additions & 0 deletions
2
regression-tests/test-results/pure2-template-specialization.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-template-specialization.cpp2... ok (all Cpp2, passes safety checks) | ||
|
Oops, something went wrong.