Skip to content

Commit 37f5cd5

Browse files
hsutterMarekKnapek
authored andcommitted
Emit object aliases using the same Cpp1 initialization { } syntax as objects
Closes hsutter#1104
1 parent 9c71ce8 commit 37f5cd5

12 files changed

+44
-43
lines changed

regression-tests/test-results/clang-12-c++20/mixed-bugfix-for-ufcs-non-local.cpp.output

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mixed-bugfix-for-ufcs-non-local.cpp2:13:12: error: a lambda expression cannot appear in this context
2-
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_1> bool inline constexpr v0 = false;// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
2+
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_1> bool inline constexpr v0{ false };// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
33
^
44
../../../include/cpp2util.h:1171:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
55
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,CPP2_UFCS_IDENTITY,CPP2_UFCS_IDENTITY,(),,__VA_ARGS__)
@@ -8,7 +8,7 @@ template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_1> bool inline constexpr
88
#define CPP2_UFCS_(LAMBDADEFCAPT,SFINAE,MVFWD,QUALID,TEMPKW,...) \
99
^
1010
mixed-bugfix-for-ufcs-non-local.cpp2:15:3: error: a lambda expression cannot appear in this context
11-
t<CPP2_UFCS_NONLOCAL(f)(o)> inline constexpr v1 = t<true>();// Fails on Clang 12 (lambda in unevaluated context).
11+
t<CPP2_UFCS_NONLOCAL(f)(o)> inline constexpr v1{ t<true>() };// Fails on Clang 12 (lambda in unevaluated context).
1212
^
1313
../../../include/cpp2util.h:1171:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
1414
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,CPP2_UFCS_IDENTITY,CPP2_UFCS_IDENTITY,(),,__VA_ARGS__)
@@ -53,7 +53,7 @@ template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_3> using a = bool;// Fail
5353
#define CPP2_UFCS_(LAMBDADEFCAPT,SFINAE,MVFWD,QUALID,TEMPKW,...) \
5454
^
5555
mixed-bugfix-for-ufcs-non-local.cpp2:33:12: error: a lambda expression cannot appear in this context
56-
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_4> auto inline constexpr b = false;// Fails on GCC ([GCC109781][]).
56+
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_4> auto inline constexpr b{ false };// Fails on GCC ([GCC109781][]).
5757
^
5858
../../../include/cpp2util.h:1171:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
5959
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,CPP2_UFCS_IDENTITY,CPP2_UFCS_IDENTITY,(),,__VA_ARGS__)
@@ -70,9 +70,9 @@ using c = t<CPP2_UFCS_NONLOCAL(f)(o)>;// Fails on Clang 12 (lambda in unevaluate
7070
../../../include/cpp2util.h:1133:66: note: expanded from macro 'CPP2_UFCS_'
7171
#define CPP2_UFCS_(LAMBDADEFCAPT,SFINAE,MVFWD,QUALID,TEMPKW,...) \
7272
^
73-
mixed-bugfix-for-ufcs-non-local.cpp2:37:29: error: a lambda expression cannot appear in this context
74-
auto inline constexpr d = t<CPP2_UFCS_NONLOCAL(f)(o)>();// Fails on Clang 12 (lambda in unevaluated context).
75-
^
73+
mixed-bugfix-for-ufcs-non-local.cpp2:37:28: error: a lambda expression cannot appear in this context
74+
auto inline constexpr d{ t<CPP2_UFCS_NONLOCAL(f)(o)>() };// Fails on Clang 12 (lambda in unevaluated context).
75+
^
7676
../../../include/cpp2util.h:1171:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
7777
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,CPP2_UFCS_IDENTITY,CPP2_UFCS_IDENTITY,(),,__VA_ARGS__)
7878
^
@@ -106,9 +106,9 @@ mixed-bugfix-for-ufcs-non-local.cpp2:27:29: error: a lambda expression cannot ap
106106
../../../include/cpp2util.h:1133:66: note: expanded from macro 'CPP2_UFCS_'
107107
#define CPP2_UFCS_(LAMBDADEFCAPT,SFINAE,MVFWD,QUALID,TEMPKW,...) \
108108
^
109-
mixed-bugfix-for-ufcs-non-local.cpp2:41:85: error: lambda expression in an unevaluated operand
110-
inline CPP2_CONSTEXPR bool u::c = [](cpp2::impl::in<std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(f)(o))>> x) mutable -> auto { return x; }(true);// Fails on Clang 12 (lambda in unevaluated context).
111-
^
109+
mixed-bugfix-for-ufcs-non-local.cpp2:41:84: error: lambda expression in an unevaluated operand
110+
inline CPP2_CONSTEXPR bool u::c{ [](cpp2::impl::in<std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(f)(o))>> x) mutable -> auto { return x; }(true) };// Fails on Clang 12 (lambda in unevaluated context).
111+
^
112112
../../../include/cpp2util.h:1171:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
113113
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,CPP2_UFCS_IDENTITY,CPP2_UFCS_IDENTITY,(),,__VA_ARGS__)
114114
^

regression-tests/test-results/mixed-bugfix-for-ufcs-non-local.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ namespace ns {
3434

3535
// Variables.
3636

37-
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_1> bool inline constexpr v0 = false;// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
37+
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_1> bool inline constexpr v0{ false };// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
3838

39-
t<CPP2_UFCS_NONLOCAL(f)(o)> inline constexpr v1 = t<true>();// Fails on Clang 12 (lambda in unevaluated context).
39+
t<CPP2_UFCS_NONLOCAL(f)(o)> inline constexpr v1{ t<true>() };// Fails on Clang 12 (lambda in unevaluated context).
4040

41-
bool inline constexpr v2 = CPP2_UFCS_NONLOCAL(f)(o);
41+
bool inline constexpr v2{ CPP2_UFCS_NONLOCAL(f)(o) };
4242

4343
// Functions.
4444

@@ -54,11 +54,11 @@ auto g() -> void;
5454

5555
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_3> using a = bool;// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
5656

57-
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_4> auto inline constexpr b = false;// Fails on GCC ([GCC109781][]).
57+
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_4> auto inline constexpr b{ false };// Fails on GCC ([GCC109781][]).
5858

5959
using c = t<CPP2_UFCS_NONLOCAL(f)(o)>;// Fails on Clang 12 (lambda in unevaluated context) and Clang 12 (a lambda expression cannot appear in this context)
6060

61-
auto inline constexpr d = t<CPP2_UFCS_NONLOCAL(f)(o)>();// Fails on Clang 12 (lambda in unevaluated context).
61+
auto inline constexpr d{ t<CPP2_UFCS_NONLOCAL(f)(o)>() };// Fails on Clang 12 (lambda in unevaluated context).
6262

6363
class u {
6464
public: static const bool b;
@@ -94,8 +94,8 @@ auto g() -> void{
9494
[[nodiscard]] auto h() -> t<CPP2_UFCS_NONLOCAL(f)(o)> { return o; }// Fails on Clang 12 (lambda in unevaluated context).
9595

9696
#line 40 "mixed-bugfix-for-ufcs-non-local.cpp2"
97-
inline CPP2_CONSTEXPR bool u::b = CPP2_UFCS_NONLOCAL(f)(o);
98-
inline CPP2_CONSTEXPR bool u::c = [](cpp2::impl::in<std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(f)(o))>> x) mutable -> auto { return x; }(true);// Fails on Clang 12 (lambda in unevaluated context).
97+
inline CPP2_CONSTEXPR bool u::b{ CPP2_UFCS_NONLOCAL(f)(o) };
98+
inline CPP2_CONSTEXPR bool u::c{ [](cpp2::impl::in<std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(f)(o))>> x) mutable -> auto { return x; }(true) };// Fails on Clang 12 (lambda in unevaluated context).
9999
auto u::g(auto const& s, auto const& sz) -> void{
100100
if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(sz)(s) != 0) ) { cpp2::cpp2_default.report_violation(""); }}
101101

regression-tests/test-results/mixed-fixed-type-aliases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ auto test(auto const& x) -> void{
4444
}
4545

4646
#line 16 "mixed-fixed-type-aliases.cpp2"
47-
template <typename T> template<typename U> inline CPP2_CONSTEXPR bool mytype<T>::myvalue = true;
47+
template <typename T> template<typename U> inline CPP2_CONSTEXPR bool mytype<T>::myvalue{ true };
4848

4949
#line 19 "mixed-fixed-type-aliases.cpp2"
5050
[[nodiscard]] auto main(int const argc_, char** argv_) -> int{

regression-tests/test-results/pure2-bugfix-for-max-munch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//=== Cpp2 type definitions and function declarations ===========================
1313

1414
#line 1 "pure2-bugfix-for-max-munch.cpp2"
15-
template<typename T> auto inline constexpr v = 0;
15+
template<typename T> auto inline constexpr v{ 0 };
1616
#line 2 "pure2-bugfix-for-max-munch.cpp2"
1717
auto main() -> int;
1818

regression-tests/test-results/pure2-bugfix-for-ufcs-arguments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ template<typename UnnamedTypeParam1_6, typename U> [[nodiscard]] auto f([[maybe_
4848

4949
extern t m;
5050
extern t const n;
51-
template<typename UnnamedTypeParam1_7, typename U> auto inline constexpr a = n;
51+
template<typename UnnamedTypeParam1_7, typename U> auto inline constexpr a{ n };
5252

5353
extern cpp2::i32 auto_8;
5454
extern cpp2::i32 auto_9;

regression-tests/test-results/pure2-bugfix-for-ufcs-name-lookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ auto const& f{t().f()};
9090
}
9191
#line 35 "pure2-bugfix-for-ufcs-name-lookup.cpp2"
9292
{
93-
auto constexpr f = t().f();
93+
auto constexpr f{ t().f() };
9494
static_assert(f == 0);
9595
}
9696
{
97-
auto constexpr f = t().f();
97+
auto constexpr f{ t().f() };
9898
static_assert(f == 0);
9999
}
100100
{

regression-tests/test-results/pure2-bugfix-for-unbraced-function-expression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class t {
2727
[[nodiscard]] auto main() -> int;
2828

2929
#line 14 "pure2-bugfix-for-unbraced-function-expression.cpp2"
30-
auto inline constexpr x = cpp2::i32{0};
30+
auto inline constexpr x{ cpp2::i32{0} };
3131
extern cpp2::i32 y;
3232

3333
//=== Cpp2 function definitions =================================================

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ constexpr skat_game::skat_game(cpp2::impl::in<cpp2::i64> _val)
121121
constexpr auto skat_game::operator=(cpp2::impl::in<cpp2::i64> _val) -> skat_game& {
122122
_value = cpp2::unsafe_narrow<cpp2::i8>(_val);
123123
return *this; }
124-
inline CPP2_CONSTEXPR skat_game skat_game::diamonds = 9;
124+
inline CPP2_CONSTEXPR skat_game skat_game::diamonds{ 9 };
125125

126-
inline CPP2_CONSTEXPR skat_game skat_game::hearts = 10;
126+
inline CPP2_CONSTEXPR skat_game skat_game::hearts{ 10 };
127127

128-
inline CPP2_CONSTEXPR skat_game skat_game::spades = 11;
128+
inline CPP2_CONSTEXPR skat_game skat_game::spades{ 11 };
129129

130-
inline CPP2_CONSTEXPR skat_game skat_game::clubs = 12;
130+
inline CPP2_CONSTEXPR skat_game skat_game::clubs{ 12 };
131131

132-
inline CPP2_CONSTEXPR skat_game skat_game::grand = 20;
132+
inline CPP2_CONSTEXPR skat_game skat_game::grand{ 20 };
133133

134-
inline CPP2_CONSTEXPR skat_game skat_game::null = 23;
134+
inline CPP2_CONSTEXPR skat_game skat_game::null{ 23 };
135135

136136
[[nodiscard]] constexpr auto skat_game::get_raw_value() const& -> cpp2::i8 { return _value; }
137137
constexpr skat_game::skat_game()
@@ -168,9 +168,9 @@ return "invalid skat_game value";
168168
constexpr auto janus::operator=(cpp2::impl::in<cpp2::i64> _val) -> janus& {
169169
_value = cpp2::unsafe_narrow<cpp2::i8>(_val);
170170
return *this; }
171-
inline CPP2_CONSTEXPR janus janus::past = 0;
171+
inline CPP2_CONSTEXPR janus janus::past{ 0 };
172172

173-
inline CPP2_CONSTEXPR janus janus::future = 1;
173+
inline CPP2_CONSTEXPR janus janus::future{ 1 };
174174

175175
[[nodiscard]] constexpr auto janus::get_raw_value() const& -> cpp2::i8 { return _value; }
176176
constexpr janus::janus()
@@ -205,15 +205,15 @@ constexpr auto file_attributes::operator^=(file_attributes const& that) & -> voi
205205
[[nodiscard]] constexpr auto file_attributes::has(file_attributes const& that) const& -> bool { return _value & that._value; }
206206
constexpr auto file_attributes::set(file_attributes const& that) & -> void { _value |= that._value; }
207207
constexpr auto file_attributes::clear(file_attributes const& that) & -> void { _value &= ~that._value; }
208-
inline CPP2_CONSTEXPR file_attributes file_attributes::cached = 1;
208+
inline CPP2_CONSTEXPR file_attributes file_attributes::cached{ 1 };
209209

210-
inline CPP2_CONSTEXPR file_attributes file_attributes::current = 2;
210+
inline CPP2_CONSTEXPR file_attributes file_attributes::current{ 2 };
211211

212-
inline CPP2_CONSTEXPR file_attributes file_attributes::obsolete = 4;
212+
inline CPP2_CONSTEXPR file_attributes file_attributes::obsolete{ 4 };
213213

214-
inline CPP2_CONSTEXPR file_attributes file_attributes::cached_and_current = cached | current;
214+
inline CPP2_CONSTEXPR file_attributes file_attributes::cached_and_current{ cached | current };
215215

216-
inline CPP2_CONSTEXPR file_attributes file_attributes::none = 0;
216+
inline CPP2_CONSTEXPR file_attributes file_attributes::none{ 0 };
217217

218218
[[nodiscard]] constexpr auto file_attributes::get_raw_value() const& -> cpp2::u8 { return _value; }
219219
constexpr file_attributes::file_attributes()

regression-tests/test-results/pure2-last-use.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ namespace captures {
465465
auto f() -> void;
466466

467467
#line 923 "pure2-last-use.cpp2"
468-
int inline constexpr x = 0;
468+
int inline constexpr x{ 0 };
469469

470470
class t {
471471
public: std::unique_ptr<int> x;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bool testing_enabled {false};
8989

9090
#line 8 "pure2-print.cpp2"
9191
template<typename T>
92-
requires (true) inline CPP2_CONSTEXPR T outer::object_alias = 42;
92+
requires (true) inline CPP2_CONSTEXPR T outer::object_alias{ 42 };
9393
#line 9 "pure2-print.cpp2"
9494

9595
#line 12 "pure2-print.cpp2"
@@ -174,8 +174,8 @@ requires ((std::is_convertible_v<CPP2_TYPEOF(x), int> && ...)) {(std::cout << ..
174174

175175
using type_alias = array<int,10>;
176176

177-
cpp2::i8 constexpr object_alias_1 = 42;
178-
auto constexpr object_alias_2 = 42;
177+
cpp2::i8 constexpr object_alias_1{ 42 };
178+
auto constexpr object_alias_2{ 42 };
179179
std::array constexpr object_alias_3{ 4, 5, 6 };
180180

181181
#line 83 "pure2-print.cpp2"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ auto const& v2{cpp2::move(v)};
8383
}
8484

8585
#line 26 "pure2-type-and-namespace-aliases.cpp2"
86-
template <typename T> inline CPP2_CONSTEXPR int myclass2<T>::value = 42;
86+
template <typename T> inline CPP2_CONSTEXPR int myclass2<T>::value{ 42 };
8787

8888
#line 29 "pure2-type-and-namespace-aliases.cpp2"
8989
auto main() -> int{
9090
using view = std::string_view;
9191
namespace N4 = std::literals;
9292

93-
auto constexpr myfunc2 = myfunc;
93+
auto constexpr myfunc2{ myfunc };
9494
myfunc2();
9595
}
9696

source/to_cpp1.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5637,8 +5637,9 @@ class cppfront
56375637
}
56385638
// Otherwise, just emit the general expression as usual
56395639
else {
5640-
return " = "
5641-
+ print_to_string(n);
5640+
return "{ "
5641+
+ print_to_string(n)
5642+
+ " }";
56425643
}
56435644
};
56445645

0 commit comments

Comments
 (0)