... in the future, when we manage to actually avoid including <cstdio> from <string> I think we can avoid including it from <random> if we play a bit with void*. Should be safe aliasing-wise. Something like the below, completely untested.

Paolo.

////////////////


Index: include/bits/random.h
===================================================================
--- include/bits/random.h       (revision 201148)
+++ include/bits/random.h       (working copy)
@@ -1638,10 +1638,10 @@
 
     union
     {
-    FILE*        _M_file;
-    mt19937      _M_mt;
+      void*      _M_file;
+      mt19937    _M_mt;
+    };
   };
-  };
 
   /* @} */ // group random_generators
 
Index: include/std/random
===================================================================
--- include/std/random  (revision 201160)
+++ include/std/random  (working copy)
@@ -36,7 +36,6 @@
 #else
 
 #include <cmath>
-#include <cstdio> // For FILE
 #include <cstdlib>
 #include <string>
 #include <iosfwd>
Index: src/c++11/random.cc
===================================================================
--- src/c++11/random.cc (revision 201160)
+++ src/c++11/random.cc (working copy)
@@ -30,6 +30,8 @@
 # include <cpuid.h>
 #endif
 
+#include <cstdio>
+
 #ifdef _GLIBCXX_HAVE_UNISTD_H
 # include <unistd.h>
 #endif
@@ -102,7 +104,7 @@
       std::__throw_runtime_error(__N("random_device::"
                                     "random_device(const std::string&)"));
 
-    _M_file = std::fopen(fname, "rb");
+    _M_file = reinterpret_cast<void*>(std::fopen(fname, "rb"));
     if (! _M_file)
       goto fail;
   }
@@ -117,7 +119,7 @@
   random_device::_M_fini()
   {
     if (_M_file)
-      std::fclose(_M_file);
+      std::fclose(reinterpret_cast<FILE*>(_M_file));
   }
 
   random_device::result_type
@@ -130,10 +132,11 @@
 
     result_type __ret;
 #ifdef _GLIBCXX_HAVE_UNISTD_H
-    read(fileno(_M_file), reinterpret_cast<void*>(&__ret), 
sizeof(result_type));
+    read(fileno(reinterpret_cast<FILE*>(_M_file)),
+        reinterpret_cast<void*>(&__ret), sizeof(result_type));
 #else
     std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type),
-              1, _M_file);
+              1, reinterpret_cast<FILE*>(_M_file));
 #endif
     return __ret;
   }

Reply via email to