@@ -1255,7 +1255,7 @@ class cppfront
12551255
12561256 // Now we'll open the Cpp1 file
12571257 auto cpp1_filename = sourcefile.substr (0 , std::ssize (sourcefile) - 1 );
1258-
1258+
12591259 // Use explicit filename override if present,
12601260 // otherwise strip leading path
12611261 if (!flag_cpp1_filename.empty ()) {
@@ -3428,12 +3428,12 @@ class cppfront
34283428 last_was_prefixed = true ;
34293429 }
34303430
3431- // Handle the other Cpp2 postfix operators that stay postfix in Cpp1
3431+ // Handle the other Cpp2 postfix operators that stay postfix in Cpp1
34323432 // (currently '...' for expansion, not when used as a range operator)
34333433 else if (
34343434 is_postfix_operator (i->op ->type ())
34353435 && !i->last_expr // not being used as a range operator
3436- )
3436+ )
34373437 {
34383438 flush_args ();
34393439 suffix.emplace_back ( i->op ->to_string (), i->op ->position ());
@@ -3474,7 +3474,7 @@ class cppfront
34743474 }
34753475
34763476 auto print = print_to_string (
3477- *i->id_expr ,
3477+ *i->id_expr ,
34783478 false , // not a local name
34793479 i->op ->type () == lexeme::Dot || i->op ->type () == lexeme::DotDot // member access
34803480 );
@@ -4406,8 +4406,8 @@ class cppfront
44064406 {
44074407 assert (n.declaration );
44084408 auto is_param_to_namespace_scope_type =
4409- n.declaration ->parent_is_type ()
4410- && n.declaration ->parent_declaration ->parent_is_namespace ()
4409+ n.declaration ->parent_is_type ()
4410+ && n.declaration ->parent_declaration ->parent_is_namespace ()
44114411 ;
44124412
44134413 auto emit_in_phase_0 =
@@ -5033,7 +5033,7 @@ class cppfront
50335033 || n.is_swap ()
50345034 || n.is_destructor ()
50355035 || (
5036- n.my_decl
5036+ n.my_decl
50375037 && generating_move_from == n.my_decl
50385038 )
50395039 )
@@ -5047,7 +5047,7 @@ class cppfront
50475047 if (
50485048 n.is_assignment ()
50495049 || (
5050- n.my_decl
5050+ n.my_decl
50515051 && generating_assignment_from == n.my_decl
50525052 )
50535053 )
@@ -5718,8 +5718,18 @@ class cppfront
57185718 auto & a = std::get<declaration_node::an_alias>(n.type );
57195719 assert (a);
57205720
5721+ // Helper for aliases that emit as a defining declaration.
5722+ auto const type_scope_object_alias_emits_in_phase_1_only = [&]() {
5723+ assert (
5724+ n.parent_is_type ()
5725+ && n.is_object_alias ()
5726+ );
5727+ return !a->type_id
5728+ || a->type_id ->is_wildcard ();
5729+ };
5730+
57215731 // Namespace-scope aliases are emitted in phase 1,
5722- // type-scope object aliases in both phases 1 and 2, and
5732+ // type-scope object aliases is emitted in phase 1 and maybe 2, and
57235733 // function-scope aliases in phase 2
57245734 if (
57255735 (
@@ -5731,6 +5741,7 @@ class cppfront
57315741 n.parent_is_type ()
57325742 && n.is_object_alias ()
57335743 && printer.get_phase () == printer.phase2_func_defs
5744+ && !type_scope_object_alias_emits_in_phase_1_only ()
57345745 )
57355746 ||
57365747 (
@@ -5805,7 +5816,7 @@ class cppfront
58055816 // Handle object aliases:
58065817 // - at function scope, it's const&
58075818 // - at namespace scope, it's inline constexpr
5808- // - at type scope, it's also inline constexpr but see note (*) below
5819+ // - at type scope, it's also static constexpr but see note (*) below
58095820 else if (a->is_object_alias ())
58105821 {
58115822 auto type = std::string{" auto" };
@@ -5830,13 +5841,26 @@ class cppfront
58305841 }
58315842 };
58325843
5833- // (*) If this is at type scope, Cpp1 requires an out-of-line declaration dance
5834- // for some cases to work - see https://stackoverflow.com/questions/11928089/
58355844 if (n.parent_is_type ())
58365845 {
58375846 assert (n.parent_declaration ->name ());
58385847
5839- if (printer.get_phase () == printer.phase1_type_defs_func_decls ) {
5848+ if (type_scope_object_alias_emits_in_phase_1_only ()) {
5849+ if (printer.get_phase () == printer.phase1_type_defs_func_decls ) {
5850+ printer.print_cpp2 (
5851+ " static constexpr "
5852+ + type + " "
5853+ + print_to_string (*n.identifier )
5854+ + " = "
5855+ + print_to_string ( *std::get<alias_node::an_object>(a->initializer ) )
5856+ + " ;\n " ,
5857+ n.position ()
5858+ );
5859+ }
5860+ }
5861+ // At type scope, Cpp1 requires an out-of-line declaration dance
5862+ // for some cases to work - see https://stackoverflow.com/questions/11928089/
5863+ else if (printer.get_phase () == printer.phase1_type_defs_func_decls ) {
58405864 printer.print_cpp2 (
58415865 " static const "
58425866 + type + " "
@@ -6014,7 +6038,10 @@ class cppfront
60146038
60156039 // In class definitions, emit the explicit access specifier if there
60166040 // is one, or default to private for data and public for functions
6017- if (printer.get_phase () == printer.phase1_type_defs_func_decls )
6041+ if (
6042+ printer.get_phase () == printer.phase1_type_defs_func_decls
6043+ && n.identifier
6044+ )
60186045 {
60196046 if (!n.is_default_access ()) {
60206047 assert (is_in_type);
@@ -6935,8 +6962,8 @@ class cppfront
69356962 return ;
69366963 }
69376964 }
6938- printer.preempt_position_push (n.position ());
6939- emit ( *type, {}, print_to_string (*n.identifier ) );
6965+ printer.preempt_position_push (n.position ());
6966+ emit ( *type, {}, print_to_string (*n.identifier ) );
69406967 printer.preempt_position_pop ();
69416968
69426969 if (
0 commit comments