Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Rework hex literals parsing #644

Merged
merged 1 commit into from
Jun 2, 2022
Merged

C++: Rework hex literals parsing #644

merged 1 commit into from
Jun 2, 2022

Conversation

chfast
Copy link
Member

@chfast chfast commented May 16, 2022

Requires #649.

@codecov
Copy link

codecov bot commented May 16, 2022

Codecov Report

Merging #644 (fe0d43f) into master (5e3d163) will decrease coverage by 0.18%.
The diff coverage is 92.30%.

❗ Current head fe0d43f differs from pull request most recent head 20ba8bf. Consider uploading reports for the commit 20ba8bf to get more accurate results

@@            Coverage Diff             @@
##           master     #644      +/-   ##
==========================================
- Coverage   92.86%   92.68%   -0.19%     
==========================================
  Files          23       23              
  Lines        3546     3526      -20     
  Branches      375      376       +1     
==========================================
- Hits         3293     3268      -25     
- Misses        144      147       +3     
- Partials      109      111       +2     

include/evmc/evmc.hpp Outdated Show resolved Hide resolved
@chfast chfast force-pushed the hex_inline branch 3 times, most recently from f09a7da to a476d6e Compare May 20, 2022 08:44
Base automatically changed from hex_inline to master May 20, 2022 13:12
Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to rebase.

@chfast chfast marked this pull request as draft May 20, 2022 16:00
@chfast chfast force-pushed the hex_literals branch 2 times, most recently from 4fa9b27 to 67ad485 Compare May 26, 2022 07:38
@chfast chfast changed the base branch from master to hex_to_T May 26, 2022 07:39
@chfast chfast marked this pull request as ready for review May 26, 2022 07:40
byte(s, 14), byte(s, 15), byte(s, 16), byte(s, 17), byte(s, 18), byte(s, 19), byte(s, 20),
byte(s, 21), byte(s, 22), byte(s, 23), byte(s, 24), byte(s, 25), byte(s, 26), byte(s, 27),
byte(s, 28), byte(s, 29), byte(s, 30), byte(s, 31)}}};
return (s == "0") ? T{} : from_hex<T>(s).value();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, from_hex is constexpr noexcept.

Is the remove_prefix really constexpr in it though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because this is string_view so it just moves the pointer and decreases size. https://en.cppreference.com/w/cpp/string/basic_string_view/remove_prefix.

include/evmc/evmc.hpp Outdated Show resolved Hide resolved
@chfast chfast force-pushed the hex_to_T branch 5 times, most recently from 95805a2 to a65e4a9 Compare June 2, 2022 11:02
Base automatically changed from hex_to_T to master June 2, 2022 11:42
/// Converts a raw literal into value of type T.
///
/// This function is expected to be used on literals in constexpr context only.
/// In case the input is invalid the std::terminate() is called.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still valid?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the .value() result in terminate in case of std::nullopt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .value() throws an exception which will call std::terminate() because the function is noexcept. This is not great if the execution happens at runtime (can happen also for literals) but better than UB with *from_hex(). This is going to be corrected with consteval in C++20 (then execution must happen at compile time).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, clang-tidy also notice this and report warning bugprone-exception-escape.

Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good apart from teh question.

@chfast chfast merged commit f4d9b41 into master Jun 2, 2022
@chfast chfast deleted the hex_literals branch June 2, 2022 14:30
@@ -138,6 +138,7 @@ class ExampleHost : public evmc::Host

evmc_tx_context get_tx_context() const noexcept final { return tx_context; }

// NOLINTNEXTLINE(bugprone-exception-escape)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this? it's still noexcept

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants