1From 36054278304945c6aef7d44e58788ca882c67d05 Mon Sep 17 00:00:00 2001 2From: Khem Raj <raj.khem@gmail.com> 3Date: Thu, 1 Sep 2022 15:54:13 -0700 4Subject: [PATCH] sandbox: Do not use int8_t in std::uniform_int_distribution 5 6Newer versions of libc++ has dropped supporting this usecase since its 7an UB see. 8 9https://reviews.llvm.org/D114920?id=400571 10 11Fixes 12 13uniform_int_distribution.h:162:5: error: static assertion failed due to requirement '__libcpp_random_is_valid_inttype<char>::value': IntType must be a supported integer type 14 static_assert(__libcpp_random_is_valid_inttype<_IntType>::value, "IntType must be a supported integer type"); 15 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/libcereal/1.3.2+gitAUTOINC+ebef1e9298-r0/git/sandbox/performance.cpp:261:9: note: in instantiation of template class 'std::uniform_int_distribution<char>' requested here 17 c = std::uniform_int_distribution<char>(' ', '~')(gen); 18 ^ 19/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux-musl/libcereal/1.3.2+gitAUTOINC+ebef1e9298-r0/git/sandbox/performance.cpp:261:9: error: type 'std::uniform_int_distribution<char>' does not provide a call operator 20 c = std::uniform_int_distribution<char>(' ', '~')(gen); 21 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 222 errors generated. 23 24Upstream-Status: Submitted [https://github.com/USCiLab/cereal/pull/764] 25Signed-off-by: Khem Raj <raj.khem@gmail.com> 26--- 27 sandbox/performance.cpp | 4 ++-- 28 1 file changed, 2 insertions(+), 2 deletions(-) 29 30diff --git a/sandbox/performance.cpp b/sandbox/performance.cpp 31index f9307870..aca8c78c 100644 32--- a/sandbox/performance.cpp 33+++ b/sandbox/performance.cpp 34@@ -258,7 +258,7 @@ random_value(std::mt19937 & gen) 35 { 36 std::string s(std::uniform_int_distribution<int>(3, 30)(gen), ' '); 37 for(char & c : s) 38- c = std::uniform_int_distribution<char>(' ', '~')(gen); 39+ c = static_cast<char>( std::uniform_int_distribution<int>(' ', '~')(gen) ); 40 return s; 41 } 42 43@@ -277,7 +277,7 @@ std::string random_binary_string(std::mt19937 & gen) 44 { 45 std::string s(N, ' '); 46 for(auto & c : s ) 47- c = std::uniform_int_distribution<char>('0', '1')(gen); 48+ c = static_cast<char>( std::uniform_int_distribution<int>( '0', '1' )(gen) ); 49 return s; 50 } 51 52-- 532.37.3 54 55