[libcxx-commits] [libcxx] add floating point type check for uniform real distrubtion (PR #70564)

Nhat Nguyen via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 29 10:37:29 PDT 2023


https://github.com/NhatNguyen1810 updated https://github.com/llvm/llvm-project/pull/70564

>From df5032990c60eac8890535bd0ed11326c09ac044 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Sat, 28 Oct 2023 14:30:43 -0400
Subject: [PATCH 1/3] add floating point type check for uniform real
 distrubtion

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

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

>From ff8abe7f51c600716055ebeedc0b295f87ee35b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Sun, 29 Oct 2023 12:40:00 -0400
Subject: [PATCH 2/3] add floating point type check for uniform real
 distrubtion

---
 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 caccb81bff1252d..89b95f5a5bfe9d7 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 bc01323a95ba101c409bf804c3ecb859a4e8bade Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Sun, 29 Oct 2023 13:36:53 -0400
Subject: [PATCH 3/3] add floating point type check for uniform real
 distrubtion

---
 libcxx/test/libcxx/transitive_includes/cxx26.csv | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index 236dedd186c9268..1035cb418822de8 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -495,6 +495,7 @@ random iosfwd
 random limits
 random numeric
 random string
+random type_traits
 random vector
 random version
 ranges compare



More information about the libcxx-commits mailing list