Commit c0f40be 1 parent a1fb263 commit c0f40be Copy full SHA for c0f40be
File tree 1 file changed +13
-6
lines changed
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,16 @@ class URLHost {
92
92
Value value_;
93
93
HostType type_ = HostType::H_FAILED;
94
94
95
+ inline void Reset () {
96
+ using string = std::string;
97
+ switch (type_) {
98
+ case HostType::H_DOMAIN: value_.domain .~string (); break ;
99
+ case HostType::H_OPAQUE: value_.opaque .~string (); break ;
100
+ default : break ;
101
+ }
102
+ type_ = HostType::H_FAILED;
103
+ }
104
+
95
105
// Setting the string members of the union with = is brittle because
96
106
// it relies on them being initialized to a state that requires no
97
107
// destruction of old data.
@@ -101,23 +111,20 @@ class URLHost {
101
111
// These helpers are the easiest solution but we might want to consider
102
112
// just not forcing strings into an union.
103
113
inline void SetOpaque (std::string&& string) {
114
+ Reset ();
104
115
type_ = HostType::H_OPAQUE;
105
116
new (&value_.opaque ) std::string (std::move (string));
106
117
}
107
118
108
119
inline void SetDomain (std::string&& string) {
120
+ Reset ();
109
121
type_ = HostType::H_DOMAIN;
110
122
new (&value_.domain ) std::string (std::move (string));
111
123
}
112
124
};
113
125
114
126
URLHost::~URLHost () {
115
- using string = std::string;
116
- switch (type_) {
117
- case HostType::H_DOMAIN: value_.domain .~string (); break ;
118
- case HostType::H_OPAQUE: value_.opaque .~string (); break ;
119
- default : break ;
120
- }
127
+ Reset ();
121
128
}
122
129
123
130
#define ARGS (XX ) \
You can’t perform that action at this time.
0 commit comments