Skip to content

Commit bcafa7b

Browse files
committed
fix(cpp1): emit template template parameters
1 parent ecd3726 commit bcafa7b

8 files changed

+68
-9
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
t: @struct <T: <_, _: _>> type = { }
2+
3+
u: @struct <T, V: _> type = { }
4+
5+
main: () = { _ = :t<u> = (); }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
clang version 18.0.0 (https://git.uplinklabs.net/mirrors/llvm-project.git c0abd3814564a568dfc607c216e6407eaa314f46)
1+
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 3723ede3cf5324827f8fbbe7f484c2ee4d7a7204)
22
Target: x86_64-pc-linux-gnu
33
Thread model: posix
44
InstalledDir: /home/johel/root/clang-main/bin

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

Whitespace-only changes.

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

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
template<template <typename, auto> class T> class t;
10+
11+
template<typename T, auto V> class u;
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
template<template <typename, auto> class T> class t {};
17+
18+
template<typename T, auto V> class u {};
19+
20+
auto main() -> int;
21+
22+
23+
//=== Cpp2 function definitions =================================================
24+
25+
26+
#line 5 "pure2-bugfix-for-template-template-parameter.cpp2"
27+
auto main() -> int{static_cast<void>(t<u>{}); }
28+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-template-template-parameter.cpp2... ok (all Cpp2, passes safety checks)
2+

source/cppfront.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,7 +3832,8 @@ class cppfront
38323832
auto emit(
38333833
parameter_declaration_node const& n,
38343834
bool is_returns = false,
3835-
bool is_template_parameter = false
3835+
bool is_template_parameter = false,
3836+
bool emit_identifier = true
38363837
)
38373838
-> void
38383839
{
@@ -3917,9 +3918,27 @@ class cppfront
39173918
// Handle type parameters
39183919

39193920
if (n.declaration->is_type()) {
3920-
printer.print_cpp2("typename ", n.declaration->identifier->position());
39213921
assert (n.declaration->identifier);
3922-
emit(*n.declaration->identifier);
3922+
printer.print_cpp2("typename", n.declaration->identifier->position());
3923+
if (emit_identifier) {
3924+
printer.print_cpp2(" ", n.declaration->identifier->position());
3925+
emit(*n.declaration->identifier);
3926+
}
3927+
return;
3928+
}
3929+
3930+
//-----------------------------------------------------------------------
3931+
// Handle template parameters
3932+
3933+
if (n.declaration->is_template()) {
3934+
assert (n.declaration->identifier);
3935+
printer.print_cpp2("template ", n.declaration->identifier->position());
3936+
emit(*n.declaration->template_parameters, is_returns, true, false);
3937+
printer.print_cpp2(" class", n.declaration->identifier->position());
3938+
if (emit_identifier) {
3939+
printer.print_cpp2(" ", n.declaration->identifier->position());
3940+
emit(*n.declaration->identifier);
3941+
}
39233942
return;
39243943
}
39253944

@@ -3931,9 +3950,11 @@ class cppfront
39313950

39323951
if (is_template_parameter) {
39333952
emit( type_id );
3934-
printer.print_cpp2(" ", type_id.position());
3935-
assert (n.declaration->identifier);
3936-
emit(*n.declaration->identifier);
3953+
if (emit_identifier) {
3954+
printer.print_cpp2(" ", type_id.position());
3955+
assert (n.declaration->identifier);
3956+
emit(*n.declaration->identifier);
3957+
}
39373958
return;
39383959
}
39393960

@@ -4116,7 +4137,8 @@ class cppfront
41164137
auto emit(
41174138
parameter_declaration_list_node const& n,
41184139
bool is_returns = false,
4119-
bool is_template_parameter = false
4140+
bool is_template_parameter = false,
4141+
bool emit_identifier = true
41204142
)
41214143
-> void
41224144
{
@@ -4144,7 +4166,7 @@ class cppfront
41444166
}
41454167
prev_pos = x->position();
41464168
assert(x);
4147-
emit(*x, is_returns, is_template_parameter);
4169+
emit(*x, is_returns, is_template_parameter, emit_identifier);
41484170
if (!x->declaration->has_name("this")) {
41494171
first = false;
41504172
}

source/parse.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,8 @@ struct declaration_node
26032603

26042604
auto is_function_expression () const -> bool
26052605
{ return is_function() && !identifier; }
2606+
auto is_template() const -> bool
2607+
{ return template_parameters != nullptr; }
26062608

26072609
auto is_polymorphic() const // has base types or virtual functions
26082610
-> bool

0 commit comments

Comments
 (0)