Skip to content

Commit

Permalink
[clang][libcxx] renames __remove_reference
Browse files Browse the repository at this point in the history
libc++ prior to LLVM 15 has a bug in it due to it excluding
`remove_reference_t` when `__remove_reference` is available as a
compiler built-in. This went unnoticed until D116203 because it wasn't
available in any compiler.

To work around this, we're renaming `__remove_reference` to
`__remove_reference_t`.

TEST=Tested locally, tested using emscripten
  • Loading branch information
cjdb committed Aug 22, 2022
1 parent d991aa9 commit e137fb6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/TransformTypeTraits.def
Expand Up @@ -22,7 +22,7 @@ TRANSFORM_TYPE_TRAIT_DEF(RemoveCV, remove_cv)
TRANSFORM_TYPE_TRAIT_DEF(RemoveCVRef, remove_cvref)
TRANSFORM_TYPE_TRAIT_DEF(RemoveExtent, remove_extent)
TRANSFORM_TYPE_TRAIT_DEF(RemovePointer, remove_pointer)
TRANSFORM_TYPE_TRAIT_DEF(RemoveReference, remove_reference)
TRANSFORM_TYPE_TRAIT_DEF(RemoveReference, remove_reference_t)
TRANSFORM_TYPE_TRAIT_DEF(RemoveRestrict, remove_restrict)
TRANSFORM_TYPE_TRAIT_DEF(RemoveVolatile, remove_volatile)
TRANSFORM_TYPE_TRAIT_DEF(EnumUnderlyingType, underlying_type)
Expand Down
6 changes: 3 additions & 3 deletions clang/test/CodeGenCXX/mangle.cpp
Expand Up @@ -1163,9 +1163,9 @@ template <typename T> void f14(T, __remove_pointer(T)) {}
template void f14<int>(int, __remove_pointer(int));
// CHECK-LABEL: @_ZN6test553f14IiEEvT_u16__remove_pointerIS1_E

template <typename T> void f15(T, __remove_reference(T)) {}
template void f15<int>(int, __remove_reference(int));
// CHECK-LABEL: @_ZN6test553f15IiEEvT_u18__remove_referenceIS1_E
template <typename T> void f15(T, __remove_reference_t(T)) {}
template void f15<int>(int, __remove_reference_t(int));
// CHECK-LABEL: @_ZN6test553f15IiEEvT_u20__remove_reference_tIS1_E

template <typename T> void f16(T, __remove_volatile(T)) {}
template void f16<int>(int, __remove_volatile(int));
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaCXX/libstdcxx_transform_type_traits_hack.cpp
Expand Up @@ -49,9 +49,9 @@ template <class T>
using H = Same<__add_rvalue_reference<T>, __add_rvalue_reference<T>>;

template <class T>
using __remove_reference = int; // expected-warning{{keyword '__remove_reference' will be made available as an identifier here}}
using __remove_reference_t = int; // expected-warning{{keyword '__remove_reference_t' will be made available as an identifier here}}
template <class T>
using I = Same<__remove_reference<T>, __remove_reference<T>>;
using I = Same<__remove_reference_t<T>, __remove_reference_t<T>>;

template <class T>
using __remove_cvref = int; // expected-warning{{keyword '__remove_cvref' will be made available as an identifier here}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaCXX/type-traits.cpp
Expand Up @@ -3157,7 +3157,7 @@ void add_rvalue_reference() {
static_assert(__is_same(add_rvalue_reference_t<int (S::*)()>, int(S::* &&)()), "");
}

template <class T> using remove_reference_t = __remove_reference(T);
template <class T> using remove_reference_t = __remove_reference_t(T);

void check_remove_reference() {
static_assert(__is_same(remove_reference_t<void>, void), "");
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/remove_reference.h
Expand Up @@ -18,16 +18,16 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_builtin(__remove_reference)
#if __has_builtin(__remove_reference_t)
template <class _Tp>
struct remove_reference {
using type _LIBCPP_NODEBUG = __remove_reference(_Tp);
using type _LIBCPP_NODEBUG = __remove_reference_t(_Tp);
};
#else
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
#endif // __has_builtin(__remove_reference)
#endif // __has_builtin(__remove_reference_t)

#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
Expand Down

0 comments on commit e137fb6

Please sign in to comment.