Skip to content

Commit 2a52d8d

Browse files
committed
fix(cpp1): emit parents' *template-head*s of alias
1 parent d1774b1 commit 2a52d8d

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
pure2-type-and-namespace-aliases.cpp2:27:26: error: ‘template<class T> class myclass2’ used without template arguments
2-
27 | value: int == 42;
3-
| ^

regression-tests/test-results/pure2-type-and-namespace-aliases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ auto myfunc() -> void{
7979
}
8080

8181
#line 27 "pure2-type-and-namespace-aliases.cpp2"
82-
inline constexpr int myclass2::value = 42;
82+
template <typename T> inline constexpr int myclass2<T>::value = 42;
8383

8484
#line 30 "pure2-type-and-namespace-aliases.cpp2"
8585
auto main() -> int{

source/cppfront.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4905,6 +4905,30 @@ class cppfront
49054905
)
49064906
-> void
49074907
{
4908+
// Helper for declarations with parent *template-head*s.
4909+
auto const emit_parent_template_parameters = [&]() {
4910+
auto parent_template_parameters = std::string{};
4911+
auto parent = n.parent_declaration;
4912+
while (
4913+
parent
4914+
&& parent->is_type()
4915+
)
4916+
{
4917+
if (parent->requires_clause_expression) {
4918+
parent_template_parameters =
4919+
"requires( " + print_to_string(*parent->requires_clause_expression) + " )\n"
4920+
+ parent_template_parameters;
4921+
}
4922+
if (parent->template_parameters) {
4923+
parent_template_parameters =
4924+
"template " + print_to_string( *parent->template_parameters, false, true )
4925+
+ " " + parent_template_parameters;
4926+
}
4927+
parent = parent->parent_declaration;
4928+
}
4929+
printer.print_cpp2(parent_template_parameters, n.position());
4930+
};
4931+
49084932
// Helper for declarations that can have requires-clauses
49094933
auto const emit_requires_clause = [&]() {
49104934
if (
@@ -5089,10 +5113,11 @@ class cppfront
50895113
);
50905114
}
50915115
else if (printer.get_phase() == printer.phase2_func_defs) {
5116+
emit_parent_template_parameters();
50925117
printer.print_cpp2(
50935118
"inline constexpr "
50945119
+ type + " "
5095-
+ n.parent_declaration->name()->to_string() + "::"
5120+
+ type_qualification_if_any_for(n)
50965121
+ print_to_string(*n.identifier)
50975122
+ " = "
50985123
+ print_to_string( *std::get<alias_node::an_object>(a->initializer) )
@@ -5260,26 +5285,7 @@ class cppfront
52605285
&& n.initializer // only if the function has a definition (is not abstract)
52615286
)
52625287
{
5263-
auto parent_template_parameters = std::string{};
5264-
auto parent = n.parent_declaration;
5265-
while (
5266-
parent
5267-
&& parent->is_type()
5268-
)
5269-
{
5270-
if (parent->requires_clause_expression) {
5271-
parent_template_parameters =
5272-
"requires( " + print_to_string(*parent->requires_clause_expression) + " )\n"
5273-
+ parent_template_parameters;
5274-
}
5275-
if (parent->template_parameters) {
5276-
parent_template_parameters =
5277-
"template " + print_to_string( *parent->template_parameters, false, true )
5278-
+ " " + parent_template_parameters;
5279-
}
5280-
parent = parent->parent_declaration;
5281-
}
5282-
printer.print_cpp2(parent_template_parameters, n.position());
5288+
emit_parent_template_parameters();
52835289
}
52845290

52855291
// Now, emit our own template parameters

0 commit comments

Comments
 (0)