@@ -1614,7 +1614,8 @@ class cppfront
16141614 unqualified_id_node const & n,
16151615 bool in_synthesized_multi_return = false ,
16161616 bool is_local_name = true ,
1617- bool is_qualified = false
1617+ bool is_qualified = false ,
1618+ bool can_emit_template_keyword = false
16181619 )
16191620 -> void
16201621 {
@@ -1663,6 +1664,10 @@ class cppfront
16631664 printer.print_cpp2 (" CPP2_FORWARD(" , {n.position ().lineno , n.position ().colno - 8 });
16641665 }
16651666
1667+ if (can_emit_template_keyword && n.open_angle != source_position{}) {
1668+ printer.print_cpp2 (" template " , n.position ());
1669+ }
1670+
16661671 assert (n.identifier );
16671672 emit (*n.identifier , is_qualified); // inform the identifier if we know this is qualified
16681673
@@ -1755,7 +1760,7 @@ class cppfront
17551760 auto guard = finally ([&]{ looking_up.pop_back (); });
17561761
17571762 // If any parent declaration
1758- return std::any_of (current_declarations.begin () + 1 , current_declarations.end () , [&](declaration_node const * decl) {
1763+ return std::any_of (current_declarations.rbegin () , current_declarations.rend () - 1 , [&](declaration_node const * decl) {
17591764 // that can have aliases
17601765 if ((decl->is_function ()
17611766 || decl->is_type ()
@@ -1765,7 +1770,7 @@ class cppfront
17651770 {
17661771 auto & stmts = decl->initializer ->get_if <compound_statement_node>()->statements ;
17671772 // among its statements
1768- return std::any_of (stmts.begin (), stmts.end (), [&](decltype (stmts.front ())& stmt) {
1773+ return std::any_of (stmts.rbegin (), stmts.rend (), [&](decltype (stmts.front ())& stmt) {
17691774 if (auto decl = stmt->get_if <declaration_node>();
17701775 decl
17711776 && decl->is_alias ()) {
@@ -1886,12 +1891,16 @@ class cppfront
18861891 printer.print_cpp2 (" typename " , n.position ());
18871892 }
18881893
1894+ auto can_emit_template_keyword = false ;
18891895 for (auto const & id : n.ids )
18901896 {
18911897 if (id.scope_op ) {
18921898 emit (*id.scope_op );
18931899 }
1894- emit (*id.id , false , true , true ); // inform the unqualified-id that it's qualified
1900+ emit (*id.id , false , true , true , can_emit_template_keyword); // inform the unqualified-id that it's qualified
1901+ if (!can_emit_template_keyword && this ->is_dependent (*id.id )) {
1902+ can_emit_template_keyword = true ;
1903+ }
18951904 }
18961905
18971906 printer.emit_to_string ();
0 commit comments