Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 902851 - dev-libs/darts-0.32h_pre20181117064816: build failed with sys-devel/clang-16.0.0 (error: no member named 'random_shuffle' in namespace 'std')
Summary: dev-libs/darts-0.32h_pre20181117064816: build failed with sys-devel/clang-16....
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: x86 Linux
: Normal normal (vote)
Assignee: CJK Team
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks: c99-porting
  Show dependency tree
 
Reported: 2023-03-24 02:10 UTC by 464270342
Modified: 2023-05-14 14:34 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build log (darts-build-log,7.25 KB, application/octet-stream)
2023-03-24 02:10 UTC, 464270342
Details
emerge info (emerge-info,7.90 KB, text/plain)
2023-03-24 02:10 UTC, 464270342
Details
Patch using custom random_shuffle (0001-Using-custom-random_shuffle.patch,1.40 KB, patch)
2023-05-14 05:51 UTC, listout
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description 464270342 2023-03-24 02:10:01 UTC
darts build fail after clang update to 16.
I google it ,and found that "random_shuffle was deprecated in C++14 and completely removed in C++17".
So, maybe we need to add some param to make it compile as c++14?

Reproducible: Always
Comment 1 464270342 2023-03-24 02:10:29 UTC
Created attachment 858767 [details]
build log
Comment 2 464270342 2023-03-24 02:10:39 UTC
Created attachment 858769 [details]
emerge info
Comment 3 listout 2023-03-26 15:07:03 UTC
I can't reproduce this error.
Build log: http://ix.io/4rSD
Comment 4 464270342 2023-03-26 15:10:48 UTC
(In reply to listout from comment #3)
> I can't reproduce this error.
> Build log: http://ix.io/4rSD

lack of -stdlib=libc++ in your CXXFLGAS, add it and try again?
Comment 5 listout 2023-05-14 05:51:40 UTC
Created attachment 861648 [details, diff]
Patch using custom random_shuffle

Thanks, I was able to reproduce the issue. Upstream seemed to be dead (the last commit was back in 2013), hence I patched it to use random_shuffle from https://en.cppreference.com/w/cpp/algorithm/random_shuffle
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-05-14 05:56:13 UTC
(In reply to listout from comment #5)
> Created attachment 861648 [details, diff] [details, diff]
> Patch using custom random_shuffle
> 
> Thanks, I was able to reproduce the issue. Upstream seemed to be dead (the
> last commit was back in 2013), hence I patched it to use random_shuffle from
> https://en.cppreference.com/w/cpp/algorithm/random_shuffle

Notes on cppreference says:
"""
The reason for removing std::random_shuffle in C++17 is that the iterator-only version usually depends on std::rand, which is now also discussed for deprecation. (std::rand should be replaced with the classes of the <random> header, as std::rand is considered harmful.) In addition, the iterator-only std::random_shuffle version usually depends on a global state. The std::shuffle's shuffle algorithm is the preferred replacement, as it uses a URBG as its 3rd parameter. 
"""

Could you try using the std::shuffle suggestion with https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator as the 3rd param?
Comment 7 listout 2023-05-14 14:34:07 UTC
(In reply to Sam James from comment #6)
> Could you try using the std::shuffle suggestion with
> https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator as the
> 3rd param?

With http://ix.io/4vOZ

diff --git a/src/lexicon.h b/src/lexicon.h
index a2935f4..e39a1d0 100644
--- a/src/lexicon.h
+++ b/src/lexicon.h
@@ -11,6 +11,21 @@
 
 #include "./mersenne-twister.h"
 
+template<class RandomIt, class URBG>
+void shuffle_t(RandomIt first, RandomIt last, URBG&& g)
+{
+    typedef typename std::iterator_traits<RandomIt>::difference_type diff_t;
+    typedef std::uniform_int_distribution<diff_t> distr_t;
+    typedef typename distr_t::param_type param_t;
+ 
+    distr_t D;
+    for (diff_t i = last - first - 1; i > 0; --i)
+    {
+        using std::swap;
+        swap(first[i], first[D(g, param_t(0, i))]);
+    }
+}
+
 namespace Darts {
 
 class Lexicon {
@@ -60,7 +75,7 @@ class Lexicon {
   void randomize() {
     Darts::MersenneTwister mt(
         static_cast<Darts::MersenneTwister::int_type>(std::time(NULL)));
-    std::random_shuffle(keys_.begin(), keys_.end(), mt);
+    shuffle_t(keys_.begin(), keys_.end(), mt);
   }
 
   void split();

I get http://ix.io/4vOY