Skip to content

Commit a07705f

Browse files
committed
fix(cpp1): do not emit TTP parameter names
1 parent 9eba37a commit a07705f

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
t: @struct <T: <_>> type = { }
1+
t: @struct <T: <_, _: _>> type = { }
22

3-
u: @struct <T: type> type = { }
3+
u: @struct <T, V: _> type = { }
44

55
main: () = { _ = :t<u> = (); }

regression-tests/test-results/pure2-bugfix-for-template-template-parameter.cpp

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

99
#line 1 "pure2-bugfix-for-template-template-parameter.cpp2"
10-
template<template <typename _> class T> class t;
10+
template<template <typename, auto> class T> class t;
1111

12-
template<typename T> class u;
12+
template<typename T, auto V> class u;
1313

1414

1515
//=== Cpp2 type definitions and function declarations ===========================
1616

1717
#line 1 "pure2-bugfix-for-template-template-parameter.cpp2"
18-
template<template <typename _> class T> class t {};
18+
template<template <typename, auto> class T> class t {};
1919

20-
template<typename T> class u {};
20+
template<typename T, auto V> class u {};
2121

2222
auto main() -> int;
2323

source/cppfront.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,7 +3828,8 @@ class cppfront
38283828
auto emit(
38293829
parameter_declaration_node const& n,
38303830
bool is_returns = false,
3831-
bool is_template_parameter = false
3831+
bool is_template_parameter = false,
3832+
bool emit_identifier = true
38323833
)
38333834
-> void
38343835
{
@@ -3914,8 +3915,11 @@ class cppfront
39143915

39153916
if (n.declaration->is_type()) {
39163917
assert (n.declaration->identifier);
3917-
printer.print_cpp2("typename ", n.declaration->identifier->position());
3918-
emit(*n.declaration->identifier);
3918+
printer.print_cpp2("typename", n.declaration->identifier->position());
3919+
if (emit_identifier) {
3920+
printer.print_cpp2(" ", n.declaration->identifier->position());
3921+
emit(*n.declaration->identifier);
3922+
}
39193923
return;
39203924
}
39213925

@@ -3925,9 +3929,12 @@ class cppfront
39253929
if (n.declaration->is_template()) {
39263930
assert (n.declaration->identifier);
39273931
printer.print_cpp2("template ", n.declaration->identifier->position());
3928-
emit(*n.declaration->template_parameters);
3929-
printer.print_cpp2(" class ", n.declaration->identifier->position());
3930-
emit(*n.declaration->identifier);
3932+
emit(*n.declaration->template_parameters, is_returns, true, false);
3933+
printer.print_cpp2(" class", n.declaration->identifier->position());
3934+
if (emit_identifier) {
3935+
printer.print_cpp2(" ", n.declaration->identifier->position());
3936+
emit(*n.declaration->identifier);
3937+
}
39313938
return;
39323939
}
39333940

@@ -3939,9 +3946,11 @@ class cppfront
39393946

39403947
if (is_template_parameter) {
39413948
emit( type_id );
3942-
printer.print_cpp2(" ", type_id.position());
3943-
assert (n.declaration->identifier);
3944-
emit(*n.declaration->identifier);
3949+
if (emit_identifier) {
3950+
printer.print_cpp2(" ", type_id.position());
3951+
assert (n.declaration->identifier);
3952+
emit(*n.declaration->identifier);
3953+
}
39453954
return;
39463955
}
39473956

@@ -4123,8 +4132,9 @@ class cppfront
41234132
//
41244133
auto emit(
41254134
parameter_declaration_list_node const& n,
4126-
bool is_returns = false,
4127-
bool is_template_parameter = false
4135+
bool is_returns = false,
4136+
bool is_template_parameter = false,
4137+
bool emit_identifier = true
41284138
)
41294139
-> void
41304140
{
@@ -4152,7 +4162,7 @@ class cppfront
41524162
}
41534163
prev_pos = x->position();
41544164
assert(x);
4155-
emit(*x, is_returns, is_template_parameter);
4165+
emit(*x, is_returns, is_template_parameter, emit_identifier);
41564166
if (!x->declaration->has_name("this")) {
41574167
first = false;
41584168
}

0 commit comments

Comments
 (0)