@@ -1614,7 +1614,8 @@ class cppfront
1614
1614
unqualified_id_node const & n,
1615
1615
bool in_synthesized_multi_return = false ,
1616
1616
bool is_local_name = true ,
1617
- bool is_qualified = false
1617
+ bool is_qualified = false ,
1618
+ bool can_emit_template_keyword = false
1618
1619
)
1619
1620
-> void
1620
1621
{
@@ -1663,6 +1664,10 @@ class cppfront
1663
1664
printer.print_cpp2 (" CPP2_FORWARD(" , {n.position ().lineno , n.position ().colno - 8 });
1664
1665
}
1665
1666
1667
+ if (can_emit_template_keyword && n.open_angle != source_position{}) {
1668
+ printer.print_cpp2 (" template " , n.position ());
1669
+ }
1670
+
1666
1671
assert (n.identifier );
1667
1672
emit (*n.identifier , is_qualified); // inform the identifier if we know this is qualified
1668
1673
@@ -1755,7 +1760,7 @@ class cppfront
1755
1760
auto guard = finally ([&]{ looking_up.pop_back (); });
1756
1761
1757
1762
// 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) {
1759
1764
// that can have aliases
1760
1765
if ((decl->is_function ()
1761
1766
|| decl->is_type ()
@@ -1765,7 +1770,7 @@ class cppfront
1765
1770
{
1766
1771
auto & stmts = decl->initializer ->get_if <compound_statement_node>()->statements ;
1767
1772
// 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) {
1769
1774
if (auto decl = stmt->get_if <declaration_node>();
1770
1775
decl
1771
1776
&& decl->is_alias ()) {
@@ -1886,12 +1891,16 @@ class cppfront
1886
1891
printer.print_cpp2 (" typename " , n.position ());
1887
1892
}
1888
1893
1894
+ auto can_emit_template_keyword = false ;
1889
1895
for (auto const & id : n.ids )
1890
1896
{
1891
1897
if (id.scope_op ) {
1892
1898
emit (*id.scope_op );
1893
1899
}
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
+ }
1895
1904
}
1896
1905
1897
1906
printer.emit_to_string ();
0 commit comments