[libcxx-commits] [PATCH] D116125: [libcxx] Fix building on Windows after 346ef5e5879e9143fe008c35c3dd6ea3c402634a

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 21 13:09:45 PST 2021


mstorsjo created this revision.
mstorsjo added a reviewer: ldionne.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

That commit, while intended to be NFC, wasn't.

libcxx/src/random.cpp used to first include <__config>, which used
to define _LIBCPP_USING_WIN32_RANDOM (but which doesn't include
any other system headers). After that, it checked for
_LIBCPP_USING_WIN32_RANDOM, and conditionally defined _CRT_RAND_S.
This was defined before including any further headers, as this has
to be defined for the declaration of rand_s() to be visible, and
has to be defined before including stdlib.h.

After that commit, _LIBCPP_USING_WIN32_RANDOM was defined only
later, in __random/random_device.h (which is included in
<random>). But we can't define _CRT_RAND_S after that, because
stdlib.h probably has been pulled in already at that point.

Instead loosen the criteria for defining _CRT_RAND_S to
_LIBCPP_WIN32API, which practically is defined exactly when
_LIBCPP_USING_WIN32_RANDOM is defined.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116125

Files:
  libcxx/src/random.cpp


Index: libcxx/src/random.cpp
===================================================================
--- libcxx/src/random.cpp
+++ libcxx/src/random.cpp
@@ -8,7 +8,7 @@
 
 #include <__config>
 
-#if defined(_LIBCPP_USING_WIN32_RANDOM)
+#if defined(_LIBCPP_WIN32API)
     // Must be defined before including stdlib.h to enable rand_s().
 #   define _CRT_RAND_S
 #endif // defined(_LIBCPP_USING_WIN32_RANDOM)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116125.395742.patch
Type: text/x-patch
Size: 403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211221/962bbe0d/attachment.bin>


More information about the libcxx-commits mailing list