[libcxx-commits] [PATCH] D65034: [libc++] use constexpr for sizeof comparisons

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 22 14:07:46 PDT 2019


ldionne added inline comments.


================
Comment at: include/functional:1769
             _FunAlloc __af(__a);
-            if (sizeof(_Fun) <= sizeof(__buf_) &&
+            if _LIBCPP_CONSTEXPR_AFTER_CXX14(sizeof(_Fun) <= sizeof(__buf_) &&
                 is_nothrow_copy_constructible<_Fp>::value &&
----------------
asomers wrote:
> ldionne wrote:
> > The purpose of `_LIBCPP_CONSTEXPR_AFTER_CXX14` isn't to be used that way, it's meant for Standard Library facilities that were marked `constexpr` in C++17. I think we should have a macro specifically for constructing an `if constexpr` when supported.
> How about something like this:
> ```
> #ifdef __cpp_if_constexpr
> #define __IF_CONSTEXPR constexpr
> #else
> #define __IF_CONSTEXPR
> #endif
> ```
Yes, except it should be `#define _LIBCPP_IF_CONSTEXPR`. I'm also unsure about this whole thing: for anything that requires `if constexpr` for correctness, we can't use `_LIBCPP_IF_CONSTEXPR` (because it's required for correctness). So this will only be useful for cases where we want to use `if constexpr` instead of just `if` as a QOI matter, and it's not clear to me this is worth introducing a macro. So I'm kind of ambivalent between `_LIBCPP_IF_CONSTEXPR` and just having the `#if __cpp_if_constexpr` check right there in the code. Thoughts?


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D65034





More information about the libcxx-commits mailing list