[libcxx-commits] [PATCH] D97365: [libc++] [C++2b] [P1682] Add to_underlying.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 4 11:51:13 PST 2021


Mordante added inline comments.


================
Comment at: libcxx/include/utility:1632
+__to_underlying(_Tp __val) noexcept {
+  return static_cast<typename underlying_type<_Tp>::type>(__val);
+}
----------------
curdeius wrote:
> zoecarver wrote:
> > Nit: you could use `underlying_type_t` here.
> I can't, it's C++14 onwards.
> 
> ```
> #if _LIBCPP_STD_VER > 11
> template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
> #endif
> ```
> Nit: you could use `underlying_type_t` here.

I asked for C++11 support so I can use it in D97115.


================
Comment at: libcxx/test/std/utilities/utility/utility.underlying/to_underlying.fail.cpp:9
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2a
+
----------------
Quuxplusone wrote:
> curdeius wrote:
> > zoecarver wrote:
> > > Are we going to retire the `c++2a` alias at some point? Maybe this should be `c++20` instead. 
> > Hmm, when all compilers we support will accept `-std=c++20`?
> > IIUC, that's because lit std param is verified by injecting into `-std=...`, so we can't just use `c++20` on a compiler that only accepts `-std=c++2a`.
> > Maybe there's some clever hack on lit params to translate c++20 into c++2a if the former isn't supported.
> > But I haven't looked into it.
> My (untested) impression is that
> - we cannot change only this `c++2a` to `c++20`, because this needs to exactly match llvm-lit's name `--param std=c++2a`
> - we SHOULD change llvm-lit to use `--param std=c++20`, AND to add `--param std=c++2b` at the same time; but this change is above my pay grade
> - one reason that change is difficult is because llvm-lit's `--param std=c++XX` relates, in some (non-obvious-to-me) way, to whether the actual compiler supports a `-std=c++XX` option. That entanglement SHOULD NOT exist, but it does. (We SHOULD just teach llvm-lit to map `std=c++20` onto `-std=c++{20,2a}` depending on compiler support.)
> - and maybe the above change would require re-configuring or re-deploying buildkite and/or other infrastructure in ways that a simple "git push" wouldn't accomplish. I don't know and am scared to assume.
There's already support for `c++2b`. Personally I don't mind `2a` in our tests and once all supported platforms support `-std=c++20` we can change it in one go. Or would you also prefer to use `23` already? I get the impression the Standard committee feels more comfortable about their 3 year schedule and are already using C++23 instead of C++2b. (Note I'm not a member of the committee.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97365



More information about the libcxx-commits mailing list