From eaa4f041f7864d9612ac2167cbe8925b2ea017d1 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Thu, 17 Nov 2022 10:33:08 -0500 Subject: [PATCH] [libc++] Use numeric_limits instead of raw INT_MAX This allows discard_block_engine to work on platforms that might not provide a full header. Differential Revision: https://reviews.llvm.org/D138212 --- libcxx/include/__random/discard_block_engine.h | 6 ++++-- libcxx/include/random | 1 + libcxx/test/libcxx/transitive_includes/cxx2b.csv | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libcxx/include/__random/discard_block_engine.h b/libcxx/include/__random/discard_block_engine.h index 57f454b560d2..db33623d9485 100644 --- a/libcxx/include/__random/discard_block_engine.h +++ b/libcxx/include/__random/discard_block_engine.h @@ -12,8 +12,8 @@ #include <__config> #include <__random/is_seed_sequence.h> #include <__utility/move.h> -#include #include +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -33,7 +33,9 @@ class _LIBCPP_TEMPLATE_VIS discard_block_engine static_assert( 0 < __r, "discard_block_engine invalid parameters"); static_assert(__r <= __p, "discard_block_engine invalid parameters"); - static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); +#ifndef _LIBCPP_CXX03_LANG // numeric_limits::max() is not constexpr in C++03 + static_assert(__r <= numeric_limits::max(), "discard_block_engine invalid parameters"); +#endif public: // types typedef typename _Engine::result_type result_type; diff --git a/libcxx/include/random b/libcxx/include/random index f8077f10c17f..5fe4906cb027 100644 --- a/libcxx/include/random +++ b/libcxx/include/random @@ -1729,6 +1729,7 @@ class piecewise_linear_distribution #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 # include +# include # include # include # include diff --git a/libcxx/test/libcxx/transitive_includes/cxx2b.csv b/libcxx/test/libcxx/transitive_includes/cxx2b.csv index b00cba3aa7a8..c8750c2703f2 100644 --- a/libcxx/test/libcxx/transitive_includes/cxx2b.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx2b.csv @@ -502,7 +502,6 @@ queue type_traits queue vector queue version random bit -random climits random cmath random cstddef random cstdint