Skip to content

Commit c6da6dc

Browse files
committed
fix: allow full specialization with metafunction
1 parent 996d0c7 commit c6da6dc

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

regression-tests/pure2-template-specialization.cpp2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ t: @struct <T: type> type = {
44
t: @struct <T: type> type < T> type requires std::is_void_v < T> = {
55
b: i32 = 2;
66
}
7+
t: @struct type < i64> type = {
8+
c: i32 = 3;
9+
}
710
v: <T> i32 = 1; // clang-format off
811
v: <> type<void> i32 = 2; // clang-format on
912
main: () = {
1013
[[assert Testing: t<i32>().a == 1]]
1114
[[assert Testing: t<void>().b == 2]]
15+
[[assert Testing: t<i64>().c == 3]]
1216
[[assert Testing: (v<i32>) == 1]]
1317
[[assert Testing: (v<void>) == 2]]
1418
}

regression-tests/test-results/pure2-template-specialization.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ template<typename T> class t {
1919
template<typename T> requires( std::is_void_v<T> )
2020
class t<T> {public: cpp2::i32 b {2};
2121
};
22+
template<> class t<cpp2::i64> {
23+
public: cpp2::i32 c {3};
24+
};
2225
template<typename T> extern cpp2::i32 v;// clang-format off
2326
// clang-format on
2427
auto main() -> int;
@@ -27,12 +30,13 @@ auto main() -> int;
2730
//=== Cpp2 function definitions =================================================
2831

2932

30-
#line 7 "pure2-template-specialization.cpp2"
33+
#line 10 "pure2-template-specialization.cpp2"
3134
template<typename T> cpp2::i32 v {1};
3235
template<> cpp2::i32 v<void> {2};
3336
auto main() -> int{
3437
cpp2::Testing.expects(t<cpp2::i32>().a==1, "");
3538
cpp2::Testing.expects(t<void>().b==2, "");
39+
cpp2::Testing.expects(t<cpp2::i64>().c==3, "");
3640
cpp2::Testing.expects((v<cpp2::i32>)==1, "");
3741
cpp2::Testing.expects((v<void>)==2, "");
3842
}

source/cppfront.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5153,7 +5153,7 @@ class cppfront
51535153

51545154
// Now, emit our own template parameters
51555155
if (
5156-
n.template_parameters
5156+
(n.template_parameters || n.is_specialization())
51575157
&& (
51585158
printer.get_phase() < printer.phase2_func_defs
51595159
|| n.is_object()
@@ -5171,7 +5171,12 @@ class cppfront
51715171
)
51725172
{
51735173
printer.print_cpp2("template", n.position());
5174-
emit(*n.template_parameters, false, true);
5174+
if (n.template_parameters) {
5175+
emit(*n.template_parameters, false, true);
5176+
} else {
5177+
assert(n.is_specialization());
5178+
printer.print_cpp2("<>", n.position());
5179+
}
51755180
printer.print_cpp2(" ", n.position());
51765181
}
51775182

0 commit comments

Comments
 (0)