Skip to content

Commit

Permalink
[libc++] <type_traits>: Avoid instantiating a pointer type.
Browse files Browse the repository at this point in the history
GCC expands the pointer type in this conditional expression even for
template types _Up that are not arrays.  This raises an error when
std::decay<> is used with reference types (as is done in LLVM's
sources).  Using add_pointer<> causes GCC to only instantiate a
pointer type for array types.

Reviewed By: #libc, philnik, ldionne

Differential Revision: https://reviews.llvm.org/D135469
  • Loading branch information
bsdjhb committed Nov 21, 2022
1 parent d9ae078 commit 26068c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libcxx/include/__type_traits/decay.h
Expand Up @@ -42,7 +42,7 @@ struct __decay<_Up, true> {
typedef _LIBCPP_NODEBUG typename conditional
<
is_array<_Up>::value,
__remove_extent_t<_Up>*,
__add_pointer_t<__remove_extent_t<_Up> >,
typename conditional
<
is_function<_Up>::value,
Expand Down
Expand Up @@ -29,10 +29,14 @@ int main(int, char**)
test_decay<int, int>();
test_decay<const volatile int, int>();
test_decay<int*, int*>();
test_decay<int&, int>();
test_decay<const volatile int&, int>();
test_decay<int[3], int*>();
test_decay<const int[3], const int*>();
test_decay<void(), void (*)()>();
#if TEST_STD_VER > 11
test_decay<int&&, int>();
test_decay<const volatile int&&, int>();
test_decay<int(int) const, int(int) const>();
test_decay<int(int) volatile, int(int) volatile>();
test_decay<int(int) &, int(int) &>();
Expand Down

0 comments on commit 26068c6

Please sign in to comment.