[libcxx-commits] [PATCH] D96946: [libcxx][RFC] Unspecified behavior randomization in libcxx

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 15 09:17:44 PST 2021


Quuxplusone added a comment.

FWIW, I think this wouldn't be too bad. I'm also not convinced it has much benefit. But here are some minor tweaks that I think would minorly increase its minor benefit and minorly decrease its minor cost:

  #if _LIBCPP_DEBUG_RANDOMIZE
   #ifdef _LIBCPP_CXX03_LANG
    #error "Randomization of unspecified behavior is available only in C++11 and later"
   #endif
   #define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) do { if (!__libcpp_is_constant_evaluated()) _VSTD::shuffle(__first, __last, __libcpp_debug_randomizer()); } while (0)
  #else
   #define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) (void)0
  #endif

This makes the changes to `sort`, `nth_element`, and `partial_sort` into one-line diffs.
Also, unless I'm missing something, you should apply the one-line diff also to `std::partition`.
I'd make the name of the macro involve `DEBUG`, but I wouldn't literally enable this as part of `_LIBCPP_DEBUG=1` or `2` or whatever.

Anyway, as usual, I'm offering tweaks that I //think// should improve this PR's chances, but making these tweaks is no guarantee of future results. ldionne is still the one to decide whether this whole direction is worthwhile at all.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96946/new/

https://reviews.llvm.org/D96946



More information about the libcxx-commits mailing list