Skip to content

Commit fe7ee05

Browse files
committed
feat(cpp1): recognize template specialization
1 parent e31cafb commit fe7ee05

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
t: @struct <T: type> type < T> type = { }
2-
main: () = { }
1+
t: @struct <T: type> type = { }
2+
t: @struct <T: type> type < T> type requires true = { }
3+
main: () = { }

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77
#include "cpp2util.h"
88

99
#line 1 "pure2-template-specialization.cpp2"
10-
template<typename T> class t;
11-
10+
template <typename T> class t;
11+
template<typename T> requires( true )
12+
class t<T>;
1213

1314
//=== Cpp2 type definitions and function declarations ===========================
1415

1516
#line 1 "pure2-template-specialization.cpp2"
16-
template<typename T> class t {};
17-
auto main() -> int;
17+
template <typename T> class t { };
18+
template<typename T> requires( true )
19+
class t<T> {};auto main() -> int;
1820

1921

2022
//=== Cpp2 function definitions =================================================
2123

2224

23-
#line 2 "pure2-template-specialization.cpp2"
24-
auto main() -> int {}
25+
#line 3 "pure2-template-specialization.cpp2"
26+
auto main() -> int {}
2527

source/cppfront.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,8 @@ class cppfront
16171617
unqualified_id_node const& n,
16181618
bool in_synthesized_multi_return = false,
16191619
bool is_local_name = true,
1620-
bool is_qualified = false
1620+
bool is_qualified = false,
1621+
bool emit_identifier = true
16211622
)
16221623
-> void
16231624
{
@@ -1667,7 +1668,9 @@ class cppfront
16671668
}
16681669

16691670
assert(n.identifier);
1670-
emit(*n.identifier, is_qualified); // inform the identifier if we know this is qualified
1671+
if (emit_identifier) {
1672+
emit(*n.identifier, is_qualified); // inform the identifier if we know this is qualified
1673+
}
16711674

16721675
if (n.open_angle != source_position{}) {
16731676
printer.print_cpp2("<", n.open_angle);
@@ -4884,6 +4887,7 @@ class cppfront
48844887
printer.get_phase() == printer.phase0_type_decls
48854888
&& !n.is_namespace()
48864889
&& !n.is_type()
4890+
&& n.specialization_template_arguments == nullptr
48874891
)
48884892
{
48894893
return;
@@ -5179,6 +5183,9 @@ class cppfront
51795183

51805184
printer.print_cpp2("class ", n.position());
51815185
emit(*n.identifier);
5186+
if (n.specialization_template_arguments) {
5187+
emit(*n.specialization_template_arguments, false, true, false, false);
5188+
}
51825189

51835190
// Type declaration
51845191
if (printer.get_phase() == printer.phase0_type_decls) {
@@ -5896,6 +5903,9 @@ class cppfront
58965903
}
58975904
else {
58985905
emit(*n.identifier);
5906+
if (n.specialization_template_arguments) {
5907+
emit(*n.specialization_template_arguments, false, true, false, false);
5908+
}
58995909
}
59005910

59015911
if (

0 commit comments

Comments
 (0)