[libcxx-commits] [libcxx] 26068c6 - [libc++] <type_traits>: Avoid instantiating a pointer type.
John Baldwin via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 21 14:34:35 PST 2022
Author: John Baldwin
Date: 2022-11-21T14:34:08-08:00
New Revision: 26068c6e60324ed866a1ca2afb5cb5eb0aaf015b
URL: https://github.com/llvm/llvm-project/commit/26068c6e60324ed866a1ca2afb5cb5eb0aaf015b
DIFF: https://github.com/llvm/llvm-project/commit/26068c6e60324ed866a1ca2afb5cb5eb0aaf015b.diff
LOG: [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
Added:
Modified:
libcxx/include/__type_traits/decay.h
libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__type_traits/decay.h b/libcxx/include/__type_traits/decay.h
index c38bbdeff21b0..f45d33b8fb4bd 100644
--- a/libcxx/include/__type_traits/decay.h
+++ b/libcxx/include/__type_traits/decay.h
@@ -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,
diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp
index af9915488f475..d07a136a59475 100644
--- a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp
+++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp
@@ -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) &>();
More information about the libcxx-commits
mailing list