[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 6 15:10:53 PDT 2022

cjdb added a comment.

In D116203#3431612 <https://reviews.llvm.org/D116203#3431612>, @rjmccall wrote:

> In D116203#3430332 <https://reviews.llvm.org/D116203#3430332>, @aaron.ballman wrote:
>> In D116203#3425512 <https://reviews.llvm.org/D116203#3425512>, @cjdb wrote:
>>> I've noticed that libstdc++ has `using __remove_cv = typename remove_cv<T>::type`, which causes Clang to chuck a wobbly. Changing from `KEYWORD` to `TYPE_TRAIT_1` didn't seem to fix anything.
>>> Is there a way we can work around this, or should we just rename `__remove_cv` and friends to something else?
>> You could work around it by taking note that you're in a libstdc++ system header and do a special dance, but because these are in the implementation's namespace, I think it's probably kinder for everyone to just pick a different name.

I was hoping we could do something similar to `struct __remove_cv` which would issue a warning?

>> If you wanted to be especially mean, you could go with `__remove_cvr`, but I'd suggest `__remove_cv_qualifiers` instead. However, what about `restrict` qualifiers? We support them in C++: https://godbolt.org/z/11EPefhjf
> Along with a fair number of other vendor qualifiers, yeah.  I think you have to make a policy decision about whether the intent of `std::remove_cv` is really to just remove CV qualifiers or to produce an unqualified type (at the outermost level).  The former is probably more defensible, even if it makes the transform less useful in the presence of extended qualifiers.

I'm partial to `std::remove_cv` being faithful to its name, unless existing implementations do something else already. I don't mind adding support for the other stuff, but if there's more than just add/remove `restrict`, we're going to have a combinatorial explosion for removes. Is there an alternate way we can approach this?

  template<class T>
  using remove_const_t = __remove_qualifiers(T, const);
  template<class T>
  using remove_reference_t = __remove_qualifiers(T, &, &&);
  template<class T>
  using remove_rcvref_t = __remove_qualifiers(T, const, volatile, restrict, &, &&); // rcv instead of cvr to prevent a typo with remove_cvref_t

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list