From b71a45630d19f210079f42f6394cdde65195fb84 Mon Sep 17 00:00:00 2001 From: Max Ihlenfeldt Date: Mon, 12 Feb 2024 16:26:09 +0000 Subject: Backport "std::pointer_traits should be SFINAE-friendly" E.g. meta-browser's Chromium recipe needs this for its 121 version update. Signed-off-by: Max Ihlenfeldt --- ...ent-LWG3545-std-pointer_traits-should-be-.patch | 660 +++++++++++++++++++++ recipes-devtools/clang/common.inc | 1 + 2 files changed, 661 insertions(+) create mode 100644 recipes-devtools/clang/clang/0035-libcxx-Implement-LWG3545-std-pointer_traits-should-be-.patch diff --git a/recipes-devtools/clang/clang/0035-libcxx-Implement-LWG3545-std-pointer_traits-should-be-.patch b/recipes-devtools/clang/clang/0035-libcxx-Implement-LWG3545-std-pointer_traits-should-be-.patch new file mode 100644 index 0000000..af86540 --- /dev/null +++ b/recipes-devtools/clang/clang/0035-libcxx-Implement-LWG3545-std-pointer_traits-should-be-.patch @@ -0,0 +1,660 @@ +From 4d11d353656c5c848ddb2c13112cf1c2f8c041c0 Mon Sep 17 00:00:00 2001 +From: Daniel Cheng +Date: Mon, 18 Sep 2023 05:46:59 -0700 +Subject: [PATCH] [libc++] Implement LWG3545: std::pointer_traits should be + SFINAE-friendly. (#65177) + +See https://wg21.link/LWG3545 for background and details. + +Differential Revision: https://reviews.llvm.org/D158922 + +Upstream-Status: Backport [https://github.com/llvm/llvm-project/pull/65177] +--- + libcxx/docs/Status/Cxx23Issues.csv | 2 +- + libcxx/include/__memory/pointer_traits.h | 17 +- + .../contiguous_iterator.verify.cpp | 54 ---- + ...to_address_without_pointer_traits.pass.cpp | 66 ++++ + .../pointer.traits/difference_type.pass.cpp | 28 -- + .../pointer.traits/element_type.pass.cpp | 28 -- + .../memory/pointer.traits/pointer.pass.cpp | 35 --- + .../memory/pointer.traits/rebind.pass.cpp | 32 -- + .../pointer.traits/types.compile.pass.cpp | 289 ++++++++++++++++++ + 9 files changed, 367 insertions(+), 184 deletions(-) + delete mode 100644 libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp + create mode 100644 libcxx/test/std/utilities/memory/pointer.conversion/to_address_without_pointer_traits.pass.cpp + delete mode 100644 libcxx/test/std/utilities/memory/pointer.traits/difference_type.pass.cpp + delete mode 100644 libcxx/test/std/utilities/memory/pointer.traits/element_type.pass.cpp + delete mode 100644 libcxx/test/std/utilities/memory/pointer.traits/pointer.pass.cpp + delete mode 100644 libcxx/test/std/utilities/memory/pointer.traits/rebind.pass.cpp + create mode 100644 libcxx/test/std/utilities/memory/pointer.traits/types.compile.pass.cpp + +diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv +index 0cc06674bda3..dc96fb2e0b50 100644 +--- a/libcxx/docs/Status/Cxx23Issues.csv ++++ b/libcxx/docs/Status/Cxx23Issues.csv +@@ -190,7 +190,7 @@ + "`3118 `__","``fpos`` equality comparison unspecified", "November 2022","","","" + "`3177 `__","Limit permission to specialize variable templates to program-defined types", "November 2022","|Nothing to do|","","" + "`3515 `__","§[stacktrace.basic.nonmem]: ``operator<<`` should be less templatized", "November 2022","","","" +-"`3545 `__","``std::pointer_traits`` should be SFINAE-friendly", "November 2022","","","" ++"`3545 `__","``std::pointer_traits`` should be SFINAE-friendly", "November 2022","|Complete|","18.0","" + "`3569 `__","``join_view`` fails to support ranges of ranges with non-default_initializable iterators", "November 2022","","","|ranges|" + "`3594 `__","``inout_ptr`` — inconsistent ``release()`` in destructor", "November 2022","","","" + "`3597 `__","Unsigned integer types don't model advanceable", "November 2022","","","|ranges|" +diff --git a/libcxx/include/__memory/pointer_traits.h b/libcxx/include/__memory/pointer_traits.h +index c33e7bd43f29..7617948ed76b 100644 +--- a/libcxx/include/__memory/pointer_traits.h ++++ b/libcxx/include/__memory/pointer_traits.h +@@ -35,7 +35,7 @@ template + struct __has_element_type<_Tp, __void_t > : true_type {}; + + template ::value> +-struct __pointer_traits_element_type; ++struct __pointer_traits_element_type {}; + + template + struct __pointer_traits_element_type<_Ptr, true> +@@ -111,12 +111,14 @@ struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> + typedef _Sp<_Up, _Args...> type; + }; + ++template ++struct __pointer_traits_impl {}; ++ + template +-struct _LIBCPP_TEMPLATE_VIS pointer_traits +-{ +- typedef _Ptr pointer; +- typedef typename __pointer_traits_element_type::type element_type; +- typedef typename __pointer_traits_difference_type::type difference_type; ++struct __pointer_traits_impl<_Ptr, __void_t::type> > { ++ typedef _Ptr pointer; ++ typedef typename __pointer_traits_element_type::type element_type; ++ typedef typename __pointer_traits_difference_type::type difference_type; + + #ifndef _LIBCPP_CXX03_LANG + template using rebind = typename __pointer_traits_rebind::type; +@@ -133,6 +135,9 @@ public: + {return pointer::pointer_to(__r);} + }; + ++template ++struct _LIBCPP_TEMPLATE_VIS pointer_traits : __pointer_traits_impl<_Ptr> {}; ++ + template + struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*> + { +diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp +deleted file mode 100644 +index 37c5ad9610a6..000000000000 +--- a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp ++++ /dev/null +@@ -1,54 +0,0 @@ +-//===----------------------------------------------------------------------===// +-// +-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +-// See https://llvm.org/LICENSE.txt for license information. +-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +-// +-//===----------------------------------------------------------------------===// +- +-// UNSUPPORTED: c++03, c++11, c++14, c++17 +- +-// This test checks that std::contiguous_iterator uses std::to_address, which is not SFINAE-friendly +-// when the type is missing the `T::element_type` typedef. +- +-#include +- +-#include +-#include +- +-struct no_element_type { +- typedef std::contiguous_iterator_tag iterator_category; +- typedef int value_type; +- typedef std::ptrdiff_t difference_type; +- typedef int* pointer; +- typedef int& reference; +- typedef no_element_type self; +- +- no_element_type(); +- +- reference operator*() const; +- pointer operator->() const; +- auto operator<=>(const self&) const = default; +- +- self& operator++(); +- self operator++(int); +- +- self& operator--(); +- self operator--(int); +- +- self& operator+=(difference_type n); +- self operator+(difference_type n) const; +- friend self operator+(difference_type n, self x); +- +- self& operator-=(difference_type n); +- self operator-(difference_type n) const; +- difference_type operator-(const self& n) const; +- +- reference operator[](difference_type n) const; +-}; +- +-void test() { +- (void) std::contiguous_iterator; +- // expected-error@*:* {{implicit instantiation of undefined template}} +- // expected-note@*:* {{to_address}} +-} +diff --git a/libcxx/test/std/utilities/memory/pointer.conversion/to_address_without_pointer_traits.pass.cpp b/libcxx/test/std/utilities/memory/pointer.conversion/to_address_without_pointer_traits.pass.cpp +new file mode 100644 +index 000000000000..4d05c10e0fbd +--- /dev/null ++++ b/libcxx/test/std/utilities/memory/pointer.conversion/to_address_without_pointer_traits.pass.cpp +@@ -0,0 +1,66 @@ ++//===----------------------------------------------------------------------===// ++// ++// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ++// See https://llvm.org/LICENSE.txt for license information. ++// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception ++// ++//===----------------------------------------------------------------------===// ++ ++// ++ ++// UNSUPPORTED: c++03, c++11, c++14, c++17 ++ ++// template constexpr auto to_address(const Ptr& p) noexcept; ++// Should not require a specialization of pointer_traits for Ptr. ++ ++#include ++#include ++#include ++ ++struct IntPtr { ++ constexpr int* operator->() const { return ptr; } ++ ++ int* ptr; ++}; ++ ++template ++struct TemplatedPtr { ++ constexpr T* operator->() const { return ptr; } ++ ++ T* ptr; ++}; ++ ++template