@@ -5080,8 +5080,18 @@ class cppfront
50805080 auto & a = std::get<declaration_node::an_alias>(n.type );
50815081 assert (a);
50825082
5083+ // Helper for aliases that emit as a defining declaration.
5084+ auto const type_scope_object_alias_emits_in_phase_1_only = [&]() {
5085+ assert (
5086+ n.parent_is_type ()
5087+ && n.is_object_alias ()
5088+ );
5089+ return !a->type_id
5090+ || a->type_id ->is_wildcard ();
5091+ };
5092+
50835093 // Namespace-scope aliases are emitted in phase 1,
5084- // type-scope object aliases in both phases 1 and 2, and
5094+ // type-scope object aliases is emitted in phase 1 and maybe 2, and
50855095 // function-scope aliases in phase 2
50865096 if (
50875097 (
@@ -5093,6 +5103,7 @@ class cppfront
50935103 n.parent_is_type ()
50945104 && n.is_object_alias ()
50955105 && printer.get_phase () == printer.phase2_func_defs
5106+ && !type_scope_object_alias_emits_in_phase_1_only ()
50965107 )
50975108 ||
50985109 (
@@ -5158,21 +5169,34 @@ class cppfront
51585169 // Handle object aliases:
51595170 // - at function scope, it's const&
51605171 // - at namespace scope, it's inline constexpr
5161- // - at type scope, it's also inline constexpr but see note (*) below
5172+ // - at type scope, it's also static constexpr but see note (*) below
51625173 else if (a->is_object_alias ())
51635174 {
51645175 auto type = std::string{" auto" };
51655176 if (a->type_id ) {
51665177 type = print_to_string (*a->type_id );
51675178 }
51685179
5169- // (*) If this is at type scope, Cpp1 requires an out-of-line declaration dance
5170- // for some cases to work - see https://stackoverflow.com/questions/11928089/
51715180 if (n.parent_is_type ())
51725181 {
51735182 assert (n.parent_declaration ->name ());
51745183
5175- if (printer.get_phase () == printer.phase1_type_defs_func_decls ) {
5184+ if (type_scope_object_alias_emits_in_phase_1_only ()) {
5185+ if (printer.get_phase () == printer.phase1_type_defs_func_decls ) {
5186+ printer.print_cpp2 (
5187+ " static constexpr "
5188+ + type + " "
5189+ + print_to_string (*n.identifier )
5190+ + " = "
5191+ + print_to_string ( *std::get<alias_node::an_object>(a->initializer ) )
5192+ + " ;\n " ,
5193+ n.position ()
5194+ );
5195+ }
5196+ }
5197+ // At type scope, Cpp1 requires an out-of-line declaration dance
5198+ // for some cases to work - see https://stackoverflow.com/questions/11928089/
5199+ else if (printer.get_phase () == printer.phase1_type_defs_func_decls ) {
51765200 printer.print_cpp2 (
51775201 " static const "
51785202 + type + " "
0 commit comments