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,25 +111,22 @@ 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 ();
106
117
value_.opaque .swap (*string);
107
118
}
108
119
109
120
inline void SetDomain (std::string* string) {
121
+ Reset ();
110
122
type_ = HostType::H_DOMAIN;
111
123
new (&value_.domain ) std::string ();
112
124
value_.domain .swap (*string);
113
125
}
114
126
};
115
127
116
128
URLHost::~URLHost () {
117
- using string = std::string;
118
- switch (type_) {
119
- case HostType::H_DOMAIN: value_.domain .~string (); break ;
120
- case HostType::H_OPAQUE: value_.opaque .~string (); break ;
121
- default : break ;
122
- }
129
+ Reset ();
123
130
}
124
131
125
132
#define ARGS (XX ) \
You can’t perform that action at this time.
0 commit comments