浏览代码

regression fixed, #15 is clear

master
Ludovic 'Archivist' Lagouardette 3 年前
父节点
当前提交
87def449a8
共有 2 个文件被更改,包括 22 次插入15 次删除
  1. +22
    -8
      include/gp/functional/optional.hpp
  2. +0
    -7
      tests/issue15_test.cpp

+ 22
- 8
include/gp/functional/optional.hpp 查看文件

@ -88,21 +88,35 @@ namespace gp{
}
optional& operator=(const optional& oth) {
if(ready) {
*(T*)buffer = oth.value();
if(oth.ready) {
if(ready) {
*(T*)buffer = oth.value();
} else {
ready = true;
new(buffer) T(oth.value());
}
} else {
ready = true;
new(buffer) T(oth.value());
if(ready) {
((T*)buffer)->~T();
ready = false;
}
}
return *this;
}
optional& operator=(optional&& oth) {
if(ready) {
*(T*)buffer = gp::move(oth.value());
if(oth.ready) {
if(ready) {
*(T*)buffer = gp::move(oth.value());
} else {
ready = true;
new(buffer) T(gp::move(oth.value()));
}
} else {
ready = true;
new(buffer) T(gp::move(oth.value()));
if(ready) {
((T*)buffer)->~T();
ready = false;
}
}
return *this;
}

+ 0
- 7
tests/issue15_test.cpp 查看文件

@ -241,13 +241,6 @@ struct packet_info_deserialization_test : public test_scaffold {
log_segment("INFO", "Item controlled");
auto [value, state] = gp::read_cbor<packet_info>(serialized.as_buffer(), allocator);
gp_config::assertion(value.has_value(), "deserialization failed");
gp_config::assertion(!state.size(), "unprocessed state remains");
gp_config::assertion(value.value().sequence == item.sequence, "comparison failed step 1");
gp_config::assertion(value.value().attempts == item.attempts, "comparison failed step 2");
gp_config::assertion(value.value().co_id == item.co_id, "comparison failed step 3");
gp_config::assertion(value.value().data == item.data, "comparison failed step 4");
return 0;
}
};

正在加载...
取消
保存