[libcxx-commits] [PATCH] D84275: [Libcxx] Finish implementing Paper 0202R3

Michael Schellenberger Costa via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 21 23:28:47 PDT 2020


miscco added a comment.

Thanks a lot for taking the time.

Unfortunately putting `_LIBCPP_CONSTEXPR_AFTER_CXX17` in front of the function is only half way through the implementation. As you can see for example in `move_backward` the implementation falls back to `_VSTD::__rotate` which is also defined in `<algorithm>`. 
Now to use `move_backward` in a `constexpr` context you need make all subsequent functions such as `__rotate` `constexpr`.  Sometimes this is easy, sometimes it is just a rabbit hole ;)

Regarding the tests I would like to point you to the `libcxx/test/std/algorithms` subfolder. For example you can find the tests for `move_backward` here: `libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp`

As you can see there is a convenient `test()` function. What you have to do is add `TEST_CONSTEXPR_CXX20` before it and then in addition to calling it at runtime also call it inside a `constexpr` context. The easiest way to do so is to simply change the function return type to `bool` and add a `return true` at the end. Then you only need to duplicate all the calls to `test` via `static_assert(test());`

Note that you would also need to guard these C++20 additions via `#if TEST_STD_VER >= 20`. I appologize that the macros are a mess each using its own selection of `after foo`, `>=foo` and `foo`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84275





More information about the libcxx-commits mailing list