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++: Literals for basic types #359

Merged
merged 5 commits into from
Jul 24, 2019
Merged

C++: Literals for basic types #359

merged 5 commits into from
Jul 24, 2019

Conversation

chfast
Copy link
Member

@chfast chfast commented Jul 22, 2019

No description provided.

test/unittests/test_cpp.cpp Outdated Show resolved Hide resolved
@chfast chfast marked this pull request as ready for review July 23, 2019 12:46
@chfast chfast requested a review from axic July 23, 2019 12:46
constexpr uint8_t parse_hex_digit(uint8_t d) noexcept
{
return static_cast<uint8_t>(
(d >= '0' && d <= '9') ? d - '0' : (d >= 'a' && d <= 'f') ? d - 'a' + 10 : d - 'A' + 10);
Copy link
Member

Choose a reason for hiding this comment

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

Any chance to abort on invalid hex digits? E.g. 0x123kkx_address ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be C++ parser error. But I've found in C++17 you can have literals like 0x0.000000000000000000000000000000000000p0_address so I added additional checks.

Copy link
Member

Choose a reason for hiding this comment

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

I reckon it is not easy to add a test case (e.g. file which would not compile)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not without creating custom testing framework in CMake.

@axic
Copy link
Member

axic commented Jul 23, 2019

Need to apply renaming to changelog.

@chfast chfast force-pushed the literals branch 2 times, most recently from 5d9a3e8 to ed8ffa4 Compare July 23, 2019 14:55
@@ -150,6 +150,110 @@ constexpr bytes32::operator bool() const noexcept
return !is_zero(*this);
}

namespace literals
{
namespace internal
Copy link
Member

Choose a reason for hiding this comment

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

Should internal stuff better go into separate header?

Copy link
Member Author

Choose a reason for hiding this comment

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

So far I'm ok with having single header for C++ (now it's even better when helpers.hpp is gone).

@chfast chfast merged commit 9b2df0f into master Jul 24, 2019
@chfast chfast deleted the literals branch July 24, 2019 12:29
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