mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Fix expected::operator*() const& and && failing to compile (#1538)
ETL_ASSERT_OR_RETURN_VALUE tried to return ETL_NULLPTR from functions returning references, which cannot be initialized from nullptr. Use plain ETL_ASSERT instead, matching the other operator*() overloads. Add regression test for dereferencing const and temporary expected. Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
This commit is contained in:
parent
70d64496e6
commit
88b629c121
@ -746,7 +746,7 @@ namespace etl
|
||||
//*******************************************
|
||||
const value_type& operator*() const ETL_LVALUE_REF_QUALIFIER
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
|
||||
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
|
||||
|
||||
return etl::get<value_type>(storage);
|
||||
}
|
||||
@ -757,7 +757,7 @@ namespace etl
|
||||
//*******************************************
|
||||
value_type&& operator*() &&
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
|
||||
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
|
||||
|
||||
return etl::move(etl::get<value_type>(storage));
|
||||
}
|
||||
|
||||
@ -618,6 +618,20 @@ namespace
|
||||
etl::expected_invalid);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// See https://github.com/ETLCPP/etl/issues/1532
|
||||
TEST(test_dereference_const_and_rvalue_expected)
|
||||
{
|
||||
typedef etl::expected<int, const char*> Expected1532;
|
||||
|
||||
Expected1532 e = 42;
|
||||
const Expected1532& ce = e;
|
||||
|
||||
CHECK_EQUAL(42, *e);
|
||||
CHECK_EQUAL(42, *ce);
|
||||
CHECK_EQUAL(42, *Expected1532(42));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
struct value_or_helper
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user