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

Pranav Tatavarthy via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 11:58:51 PDT 2023


https://github.com/Pranav10903 updated https://github.com/llvm/llvm-project/pull/70485

>From 52cb5d88e3a4bd347f6993405b18480acc0835f1 Mon Sep 17 00:00:00 2001
From: Pranav Tatavarthy <97344709+Pranav10903 at users.noreply.github.com>
Date: Fri, 27 Oct 2023 21:41:41 +0530
Subject: [PATCH 1/3] Update uniform_real_distribution.h

---
 libcxx/include/__random/uniform_real_distribution.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/include/__random/uniform_real_distribution.h b/libcxx/include/__random/uniform_real_distribution.h
index 1388cef95f39414..8268dc4f14327c0 100644
--- a/libcxx/include/__random/uniform_real_distribution.h
+++ b/libcxx/include/__random/uniform_real_distribution.h
@@ -27,6 +27,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");
 public:
     // types
     typedef _RealType result_type;

>From c846260ffb00060a4840d07b37937ed4fe14beea Mon Sep 17 00:00:00 2001
From: Pranav Tatavarthy <97344709+Pranav10903 at users.noreply.github.com>
Date: Fri, 27 Oct 2023 23:18:48 +0530
Subject: [PATCH 2/3] Update uniform_real_distribution.h

---
 libcxx/include/__random/uniform_real_distribution.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/include/__random/uniform_real_distribution.h b/libcxx/include/__random/uniform_real_distribution.h
index 8268dc4f14327c0..40a14eff7b3aed4 100644
--- a/libcxx/include/__random/uniform_real_distribution.h
+++ b/libcxx/include/__random/uniform_real_distribution.h
@@ -14,6 +14,7 @@
 #include <__random/is_valid.h>
 #include <iosfwd>
 #include <limits>
+#include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header

>From 7bab5a65a5e2e7f2ea6415f554f8e1c00dd21a45 Mon Sep 17 00:00:00 2001
From: Pranav Tatavarthy <97344709+Pranav10903 at users.noreply.github.com>
Date: Sat, 28 Oct 2023 00:28:41 +0530
Subject: [PATCH 3/3] Update uniform_real_distribution.h

---
 libcxx/include/__random/uniform_real_distribution.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__random/uniform_real_distribution.h b/libcxx/include/__random/uniform_real_distribution.h
index 40a14eff7b3aed4..095dc89d40eed7c 100644
--- a/libcxx/include/__random/uniform_real_distribution.h
+++ b/libcxx/include/__random/uniform_real_distribution.h
@@ -14,7 +14,7 @@
 #include <__random/is_valid.h>
 #include <iosfwd>
 #include <limits>
-#include <type_traits>
+#include<__type_traits/is_floating_point.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header



More information about the cfe-commits mailing list