Skip to content

Commit f9f06d3

Browse files
committed
fix(cpp1): define static data member with placeholder type in class
1 parent 88d0fa2 commit f9f06d3

File tree

4 files changed

+28
-44
lines changed

4 files changed

+28
-44
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,12 @@ myclass5: type == myclass4;
3838

3939
myclass3: @struct type = {
4040
v0 :== :std::array = (0);;
41-
v1: std::array == v0;
42-
v2: myclass3 == :myclass3 = ();;
41+
v1 :== v0; // OK: Also uses the Cpp2 placeholder type.
42+
v2: myclass3 == myclass3(); // OK: Doesn't use the Cpp2 placeholder type.
4343
v3: _ == v0;
44-
// v4 :== v2; // Not (yet) supported.
45-
// v5: myclass4 == :myclass4 = ();; // Not yet supported.
46-
// v6: myclass5 == :myclass5 = ();; // Not yet supported.
47-
// v7 :== myclass3(); // Not (yet) supported.
48-
49-
// There's also a false positive:
50-
// <https://github.com/hsutter/cppfront/issues/666#issuecomment-1722329609>.
44+
v4: myclass3 == v2; // OK: Doesn't use the Cpp2 placeholder type.
45+
v5: myclass4 == myclass4(); // OK: Doesn't use the Cpp2 placeholder type.
46+
v6: myclass5 == myclass5(); // OK: Doesn't use the Cpp2 placeholder type.
5147
}
5248

5349
myclass4: @struct type = { }

regression-tests/test-results/pure2-print.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class outer {
2222
public: template<typename T>
2323
CPP2_REQUIRES_ (true)
2424
#line 6 "pure2-print.cpp2"
25-
static constexpr T object_alias = 42;
25+
static const T object_alias;
2626

2727
public: class mytype final
2828
{
@@ -90,6 +90,12 @@ auto main() -> int;
9090
//=== Cpp2 function definitions =================================================
9191

9292

93+
#line 6 "pure2-print.cpp2"
94+
template<typename T>
95+
requires (true)
96+
#line 6 "pure2-print.cpp2"
97+
inline CPP2_CONSTEXPR T outer::object_alias = 42;
98+
9399
#line 10 "pure2-print.cpp2"
94100
[[nodiscard]] auto outer::mytype::f() -> int { return 42; }
95101

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template<typename T> class myclass2;
2424
class myclass3;
2525

2626

27-
#line 53 "pure2-type-and-namespace-aliases.cpp2"
27+
#line 49 "pure2-type-and-namespace-aliases.cpp2"
2828
class myclass4;
2929

3030
template<typename T> class myclass6;
@@ -59,7 +59,7 @@ auto myfunc() -> void;
5959

6060
#line 25 "pure2-type-and-namespace-aliases.cpp2"
6161
template<typename T> class myclass2 {
62-
public: static constexpr int value = 42;
62+
public: static const int value;
6363

6464
public: myclass2() = default;
6565
public: myclass2(myclass2 const&) = delete; /* No 'that' constructor, suppress copy */
@@ -75,24 +75,20 @@ using myclass5 = myclass4;
7575

7676
class myclass3 {
7777
public: static constexpr auto v0 = std::array{0};
78-
public: static constexpr std::array v1 = v0;
79-
public: static const myclass3 v2;
78+
public: static constexpr auto v1 = v0;// OK: Also uses the Cpp2 placeholder type.
79+
public: static const myclass3 v2;// OK: Doesn't use the Cpp2 placeholder type.
8080
public: static constexpr auto v3 = v0;
81-
// v4 :== v2; // Not (yet) supported.
82-
// v5: myclass4 == :myclass4 = ();; // Not yet supported.
83-
// v6: myclass5 == :myclass5 = ();; // Not yet supported.
84-
// v7 :== myclass3(); // Not (yet) supported.
85-
86-
// There's also a false positive:
87-
// <https://github.com/hsutter/cppfront/issues/666#issuecomment-1722329609>.
81+
public: static const myclass3 v4;// OK: Doesn't use the Cpp2 placeholder type.
82+
public: static const myclass4 v5;// OK: Doesn't use the Cpp2 placeholder type.
83+
public: static const myclass5 v6;// OK: Doesn't use the Cpp2 placeholder type.
8884
};
8985

9086
class myclass4 {};
9187

9288
template<typename T> class myclass6 {
9389
public: template<typename U>
9490
CPP2_REQUIRES_ (true)
95-
#line 56 "pure2-type-and-namespace-aliases.cpp2"
91+
#line 52 "pure2-type-and-namespace-aliases.cpp2"
9692
static constexpr auto v = 0;
9793
};
9894

@@ -118,6 +114,9 @@ auto const& v2 = std::move(v);
118114
#line 23 "pure2-type-and-namespace-aliases.cpp2"
119115
}
120116

117+
#line 26 "pure2-type-and-namespace-aliases.cpp2"
118+
template <typename T> inline CPP2_CONSTEXPR int myclass2<T>::value = 42;
119+
121120
#line 29 "pure2-type-and-namespace-aliases.cpp2"
122121
auto main() -> int{
123122
using view = std::string_view;
@@ -128,6 +127,9 @@ auto main() -> int{
128127
}
129128

130129
#line 42 "pure2-type-and-namespace-aliases.cpp2"
131-
inline CPP2_CONSTEXPR myclass3 myclass3::v2 = myclass3{};
130+
inline CPP2_CONSTEXPR myclass3 myclass3::v2 = myclass3();
132131

132+
inline CPP2_CONSTEXPR myclass3 myclass3::v4 = v2;
133+
inline CPP2_CONSTEXPR myclass4 myclass3::v5 = myclass4();
134+
inline CPP2_CONSTEXPR myclass5 myclass3::v6 = myclass5();
133135

source/cppfront.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4958,25 +4958,6 @@ class cppfront
49584958
}
49594959

49604960

4961-
auto has_potentially_incomplete_type(
4962-
declaration_node const& n,
4963-
type_id_node const& t
4964-
)
4965-
-> bool
4966-
{
4967-
auto type_id = t.get_token();
4968-
4969-
if (!type_id) {
4970-
return false;
4971-
}
4972-
4973-
if (auto parent = n.get_parent()) {
4974-
return parent->name() && *type_id == *parent->name();
4975-
}
4976-
4977-
return false;
4978-
}
4979-
49804961
//-----------------------------------------------------------------------
49814962
//
49824963
auto emit(
@@ -5098,8 +5079,7 @@ class cppfront
50985079
&& n.is_object_alias()
50995080
);
51005081
return !a->type_id
5101-
|| a->type_id->is_wildcard()
5102-
|| !has_potentially_incomplete_type(n, *a->type_id);
5082+
|| a->type_id->is_wildcard();
51035083
};
51045084

51055085
// Namespace-scope aliases are emitted in phase 1,

0 commit comments

Comments
 (0)