Skip to content

Commit

Permalink
C++: Support zero literal (0x0_address)
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Feb 13, 2023
1 parent 97fac6f commit 25431fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ namespace literals
template <typename T>
constexpr T parse(std::string_view s) noexcept
{
return from_hex<T>(s).value();
auto const v = from_hex<T>(s);
return v.has_value() ? v.value() : T{};
}

/// Literal for evmc::address.
Expand Down
6 changes: 6 additions & 0 deletions test/unittests/cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ TEST(cpp, std_hash)
std::fill_n(eb.bytes, sizeof(eb), uint8_t{0xee});
EXPECT_EQ(std::hash<evmc::bytes32>{}(eb), static_cast<size_t>(0xbb14e5c56b477375));

const auto zero_address = 0x0_address;
EXPECT_EQ(zero_address, evmc::address{});

const auto zero_bytes32 = 0x0_bytes32;
EXPECT_EQ(zero_bytes32, evmc::bytes32{});

const auto rand_address_1 = 0xaa00bb00cc00dd00ee00ff001100220033004400_address;
EXPECT_EQ(std::hash<evmc::address>{}(rand_address_1), static_cast<size_t>(0x30022347e325524e));

Expand Down

0 comments on commit 25431fb

Please sign in to comment.