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

[libc++] Fixed uniform_real_distribution.h where it was allowing initialization with non floating point types #70485

Closed
wants to merge 4 commits into from

Conversation

Pranav10903
Copy link

Included a static_assert to deal with cases where result_types are initialized with non floating point type values which can cause undefined behaviour as mentioned here

@Pranav10903 Pranav10903 requested a review from a team as a code owner October 27, 2023 17:57
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 27, 2023
Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! The code itself looks fine, but this needs a test.

libcxx/include/__random/uniform_real_distribution.h Outdated Show resolved Hide resolved
@@ -27,6 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template<class _RealType = double>
class _LIBCPP_TEMPLATE_VIS uniform_real_distribution
{
static_assert(std::is_floating_point<_RealType>::value, "result_type must be a floating point type");
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a test. You can take a look at libcxx/test/libcxx/input.output/iostream.format/input.streams/traits_mismatch.verify.cpp for an example of how to check static assertions.

@philnik777
Copy link
Contributor

You should also mention the issue in the description.

@Pranav10903
Copy link
Author

Thank you for your guidance, I will do the required changes. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants