Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is std::seed_seq non-copyable according to C++11, and why doesn't gcc/clang conform?

Consider the following minimal example:

// main.cpp
#include <random>

int main(int, char **)
{
  std::seed_seq seed1{1337, 42};
  std::seed_seq seed2(seed1);
  std::seed_seq seed3 = seed2;
  return 0;
}

According to the C++ standard, this shouldn't compile, as std::seed_seq is neither copy constructible, nor copy assignable.

However, this compiles fine with both g++ 4.9, and clang 3.4

g++-4.9 -std=c++11 -Wall main.cpp
clang++ -std=c++11 -Wall main.cpp

The android ndk's llvm-libc++ implementation seems to follow the "not copyable" property of seed_seq. Which can be confirmed in the source at

 android-ndk-r10d/sources/cxx-stl/llvm-libc++/libcxx/include/random:3553

Or by compiling the minimal example using

 ${NDK_HOME}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ \
 -std=c++11 -c -Wall \
 -I${NDK_HOME}/sources/cxx-stl/llvm-libc++/libcxx/include \
 -I${NDK_HOME}/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/include \
 -I${NDK_HOME}/sources/cxx-stl/llvm-libc++/../../android/support/include \
 -isystem ${NDK_HOME}/platforms/android-18/arch-arm/usr/include \
 main.cpp

I've previously used this (without being aware of my non-conforming code) to store a copy of the seed for logging purposes.*

I'm left wondering:

  1. Why it is that seed_seq isn't copyable?

  2. This is the first time I've encountered g++ and clang to not conform to the standard. Is it a conscious decision to deviate from the standard, or is this an implementation bug? How prevalent is this? I'd like to learn more.


* I realized that I was thinking of seed_seq wrong, and that if I'm only interested in the seed_seq::param values (the seed_seeq's initial seed values), that I should instead keep my copy in a vector<T>, instead of a type that is meant to generate integers.

like image 480
swalog Avatar asked Mar 30 '15 15:03

swalog


1 Answers

For those who see this in the future, as per T.C. and ecatmur, this is libstdc++ bug 65631. There's no ETA on a fix though; the behavior conformed with the original proposal, but this was changed to remove copyability from the concept to address LWG issue 1069, as per the N3037 paper.

like image 153
LThode Avatar answered Oct 24 '22 17:10

LThode