Skip to content

Commit 26068c6

Browse files
committed
[libc++] <type_traits>: Avoid instantiating a pointer type.
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
1 parent d9ae078 commit 26068c6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

libcxx/include/__type_traits/decay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct __decay<_Up, true> {
4242
typedef _LIBCPP_NODEBUG typename conditional
4343
<
4444
is_array<_Up>::value,
45-
__remove_extent_t<_Up>*,
45+
__add_pointer_t<__remove_extent_t<_Up> >,
4646
typename conditional
4747
<
4848
is_function<_Up>::value,

libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ int main(int, char**)
2929
test_decay<int, int>();
3030
test_decay<const volatile int, int>();
3131
test_decay<int*, int*>();
32+
test_decay<int&, int>();
33+
test_decay<const volatile int&, int>();
3234
test_decay<int[3], int*>();
3335
test_decay<const int[3], const int*>();
3436
test_decay<void(), void (*)()>();
3537
#if TEST_STD_VER > 11
38+
test_decay<int&&, int>();
39+
test_decay<const volatile int&&, int>();
3640
test_decay<int(int) const, int(int) const>();
3741
test_decay<int(int) volatile, int(int) volatile>();
3842
test_decay<int(int) &, int(int) &>();

0 commit comments

Comments
 (0)