Skip to content

Commit 26a4cbf

Browse files
committed
Minor enum and union tidying
1 parent f44dda9 commit 26a4cbf

File tree

7 files changed

+322
-239
lines changed

7 files changed

+322
-239
lines changed

Diff for: regression-tests/test-results/pure2-enum.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class file_attributes;
2424

2525
#line 2 "pure2-enum.cpp2"
2626
class skat_game {
27-
private: cpp2::i8 _value; private: constexpr skat_game(auto const& val);
27+
private: cpp2::i8 _value; private: constexpr skat_game(cpp2::in<cpp2::i64> val);
2828

29-
private: constexpr auto operator=(auto const& val) -> skat_game& ;
29+
private: constexpr auto operator=(cpp2::in<cpp2::i64> val) -> skat_game& ;
3030
public: [[nodiscard]] constexpr auto get_raw_value() const& -> cpp2::i8;
3131
public: constexpr skat_game(skat_game const& that);
3232
public: constexpr auto operator=(skat_game const& that) -> skat_game& ;
@@ -55,9 +55,9 @@ class janus {
5555
#line 15 "pure2-enum.cpp2"
5656
public: auto flip() & -> void;
5757

58-
private: cpp2::i8 _value; private: constexpr janus(auto const& val);
58+
private: cpp2::i8 _value; private: constexpr janus(cpp2::in<cpp2::i64> val);
5959

60-
private: constexpr auto operator=(auto const& val) -> janus& ;
60+
private: constexpr auto operator=(cpp2::in<cpp2::i64> val) -> janus& ;
6161
public: [[nodiscard]] constexpr auto get_raw_value() const& -> cpp2::i8;
6262
public: constexpr janus(janus const& that);
6363
public: constexpr auto operator=(janus const& that) -> janus& ;
@@ -73,9 +73,9 @@ public: friend auto operator<<(std::ostream& o, cpp2::in<janus> val) -> std::ost
7373
};
7474

7575
class file_attributes {
76-
private: cpp2::u8 _value; private: constexpr file_attributes(auto const& val);
76+
private: cpp2::u8 _value; private: constexpr file_attributes(cpp2::in<cpp2::i64> val);
7777

78-
private: constexpr auto operator=(auto const& val) -> file_attributes& ;
78+
private: constexpr auto operator=(cpp2::in<cpp2::i64> val) -> file_attributes& ;
7979
public: [[nodiscard]] constexpr auto get_raw_value() const& -> cpp2::u8;
8080
public: constexpr file_attributes(file_attributes const& that);
8181
public: constexpr auto operator=(file_attributes const& that) -> file_attributes& ;
@@ -114,11 +114,11 @@ auto main() -> int;
114114

115115

116116

117-
constexpr skat_game::skat_game(auto const& val)
118-
: _value{ cpp2::unsafe_narrow<cpp2::i8>(val) } { }
119-
constexpr auto skat_game::operator=(auto const& val) -> skat_game& {
120-
_value = cpp2::unsafe_narrow<cpp2::i8>(val);
121-
return *this; }
117+
constexpr skat_game::skat_game(cpp2::in<cpp2::i64> val)
118+
: _value{ cpp2::unsafe_narrow<cpp2::i8>(val) } { }
119+
constexpr auto skat_game::operator=(cpp2::in<cpp2::i64> val) -> skat_game& {
120+
_value = cpp2::unsafe_narrow<cpp2::i8>(val);
121+
return *this; }
122122
[[nodiscard]] constexpr auto skat_game::get_raw_value() const& -> cpp2::i8 { return _value; }
123123
constexpr skat_game::skat_game(skat_game const& that)
124124
: _value{ that._value }{}
@@ -160,12 +160,12 @@ inline constexpr skat_game skat_game::null = 23;
160160
}
161161

162162

163-
constexpr janus::janus(auto const& val)
164-
: _value{ cpp2::unsafe_narrow<cpp2::i8>(val) } { }
163+
constexpr janus::janus(cpp2::in<cpp2::i64> val)
164+
: _value{ cpp2::unsafe_narrow<cpp2::i8>(val) } { }
165165

166-
constexpr auto janus::operator=(auto const& val) -> janus& {
167-
_value = cpp2::unsafe_narrow<cpp2::i8>(val);
168-
return *this; }
166+
constexpr auto janus::operator=(cpp2::in<cpp2::i64> val) -> janus& {
167+
_value = cpp2::unsafe_narrow<cpp2::i8>(val);
168+
return *this; }
169169
[[nodiscard]] constexpr auto janus::get_raw_value() const& -> cpp2::i8 { return _value; }
170170
constexpr janus::janus(janus const& that)
171171
: _value{ that._value }{}
@@ -188,11 +188,11 @@ inline constexpr janus janus::future = 1;
188188
}
189189

190190
auto operator<<(std::ostream& o, cpp2::in<janus> val) -> std::ostream&{o << CPP2_UFCS_0(to_string, val);return o; }
191-
constexpr file_attributes::file_attributes(auto const& val)
192-
: _value{ cpp2::unsafe_narrow<cpp2::u8>(val) } { }
193-
constexpr auto file_attributes::operator=(auto const& val) -> file_attributes& {
194-
_value = cpp2::unsafe_narrow<cpp2::u8>(val);
195-
return *this; }
191+
constexpr file_attributes::file_attributes(cpp2::in<cpp2::i64> val)
192+
: _value{ cpp2::unsafe_narrow<cpp2::u8>(val) } { }
193+
constexpr auto file_attributes::operator=(cpp2::in<cpp2::i64> val) -> file_attributes& {
194+
_value = cpp2::unsafe_narrow<cpp2::u8>(val);
195+
return *this; }
196196
[[nodiscard]] constexpr auto file_attributes::get_raw_value() const& -> cpp2::u8 { return _value; }
197197
constexpr file_attributes::file_attributes(file_attributes const& that)
198198
: _value{ that._value }{}

Diff for: regression-tests/test-results/pure2-union.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ auto name_or_number::set_num(auto&& ...args) & -> void{if (!(is_num())) {destroy
6161
auto name_or_number::destroy() & -> void{
6262
if (_discriminator == 0) {std::destroy_at(reinterpret_cast<std::string*>(&_storage));}
6363
if (_discriminator == 1) {std::destroy_at(reinterpret_cast<cpp2::i32*>(&_storage));}
64+
_discriminator = -1;
6465
}
6566

6667
name_or_number::~name_or_number() noexcept{destroy();}

Diff for: regression-tests/test-results/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8925:1454
2+
cppfront compiler v0.2.1 Build 8926:1147
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

Diff for: source/build.info

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8925:1454"
1+
"8926:1147"

Diff for: source/parse.h

+4
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,10 @@ struct declaration_node
27732773
{ return type.index() == a_function; }
27742774
auto is_object () const -> bool
27752775
{ return type.index() == an_object; }
2776+
auto is_base_object() const -> bool
2777+
{ return is_object() && has_name("this"); }
2778+
auto is_member_object() const -> bool
2779+
{ return is_object() && !has_name("this"); }
27762780
auto is_concept () const -> bool
27772781
{ return type.index() == an_object && get<an_object>(type)->is_concept(); }
27782782
auto is_type () const -> bool

0 commit comments

Comments
 (0)