Skip to content

Commit f9a01b1

Browse files
committed
fix(cpp1): do not emit _template-head_ alone in phase 2
1 parent 614ac76 commit f9a01b1

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

regression-tests/pure2-type-and-namespace-aliases.cpp2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ myclass3: @struct type = {
4747
}
4848

4949
myclass4: @struct type = { }
50+
51+
myclass6: @struct <T: type> type = {
52+
v: <U> _ requires true == 0;
53+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class myclass3;
2323
#line 49 "pure2-type-and-namespace-aliases.cpp2"
2424
class myclass4;
2525

26+
template<typename T> class myclass6;
27+
2628

2729
//=== Cpp2 type definitions and function declarations ===========================
2830

@@ -73,6 +75,13 @@ class myclass3 {
7375

7476
class myclass4 {};
7577

78+
template<typename T> class myclass6 {
79+
public: template<typename U>
80+
CPP2_REQUIRES_ (true)
81+
#line 52 "pure2-type-and-namespace-aliases.cpp2"
82+
static constexpr auto v = 0;
83+
};
84+
7685

7786
//=== Cpp2 function definitions =================================================
7887

source/cppfront.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5006,8 +5006,19 @@ class cppfront
50065006
auto& a = std::get<declaration_node::an_alias>(n.type);
50075007
assert(a);
50085008

5009+
// Helper for aliases that emit as a defining declaration.
5010+
auto const type_scope_object_alias_emits_in_phase_1_only = [&]() {
5011+
assert(
5012+
n.parent_is_type()
5013+
&& n.is_object_alias()
5014+
);
5015+
return !a->type_id
5016+
|| a->type_id->is_wildcard()
5017+
|| !has_potentially_incomplete_type(n, *a->type_id);
5018+
};
5019+
50095020
// Namespace-scope aliases are emitted in phase 1,
5010-
// type-scope object aliases in both phases 1 and 2, and
5021+
// type-scope object aliases is emitted in phase 1 and maybe 2, and
50115022
// function-scope aliases in phase 2
50125023
if (
50135024
(
@@ -5019,6 +5030,7 @@ class cppfront
50195030
n.parent_is_type()
50205031
&& n.is_object_alias()
50215032
&& printer.get_phase() == printer.phase2_func_defs
5033+
&& !type_scope_object_alias_emits_in_phase_1_only()
50225034
)
50235035
||
50245036
(
@@ -5084,7 +5096,7 @@ class cppfront
50845096
// Handle object aliases:
50855097
// - at function scope, it's const&
50865098
// - at namespace scope, it's inline constexpr
5087-
// - at type scope, it's also inline constexpr but see note (*) below
5099+
// - at type scope, it's also static constexpr but see note (*) below
50885100
else if (a->is_object_alias())
50895101
{
50905102
auto type = std::string{"auto"};
@@ -5096,11 +5108,7 @@ class cppfront
50965108
{
50975109
assert (n.parent_declaration->name());
50985110

5099-
if (
5100-
!a->type_id
5101-
|| a->type_id->is_wildcard()
5102-
|| !has_potentially_incomplete_type(n, *a->type_id)
5103-
) {
5111+
if (type_scope_object_alias_emits_in_phase_1_only()) {
51045112
if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
51055113
printer.print_cpp2(
51065114
"static constexpr "

0 commit comments

Comments
 (0)