Skip to content

Commit e1b1d1e

Browse files
committed
fix(cpp1): do not emit _template-head_ alone in phase 2
1 parent 29311e3 commit e1b1d1e

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
@@ -5005,8 +5005,19 @@ class cppfront
50055005
auto& a = std::get<declaration_node::an_alias>(n.type);
50065006
assert(a);
50075007

5008+
// Helper for aliases that emit as a defining declaration.
5009+
auto const type_scope_object_alias_emits_in_phase_1_only = [&]() {
5010+
assert(
5011+
n.parent_is_type()
5012+
&& n.is_object_alias()
5013+
);
5014+
return !a->type_id
5015+
|| a->type_id->is_wildcard()
5016+
|| !has_potentially_incomplete_type(n, *a->type_id);
5017+
};
5018+
50085019
// Namespace-scope aliases are emitted in phase 1,
5009-
// type-scope object aliases in both phases 1 and 2, and
5020+
// type-scope object aliases is emitted in phase 1 and maybe 2, and
50105021
// function-scope aliases in phase 2
50115022
if (
50125023
(
@@ -5018,6 +5029,7 @@ class cppfront
50185029
n.parent_is_type()
50195030
&& n.is_object_alias()
50205031
&& printer.get_phase() == printer.phase2_func_defs
5032+
&& !type_scope_object_alias_emits_in_phase_1_only()
50215033
)
50225034
||
50235035
(
@@ -5083,7 +5095,7 @@ class cppfront
50835095
// Handle object aliases:
50845096
// - at function scope, it's const&
50855097
// - at namespace scope, it's inline constexpr
5086-
// - at type scope, it's also inline constexpr but see note (*) below
5098+
// - at type scope, it's also static constexpr but see note (*) below
50875099
else if (a->is_object_alias())
50885100
{
50895101
auto type = std::string{"auto"};
@@ -5095,11 +5107,7 @@ class cppfront
50955107
{
50965108
assert (n.parent_declaration->name());
50975109

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

0 commit comments

Comments
 (0)