[libcxx-commits] [PATCH] D121154: [libc++] Add a test for std::ssize's SFINAE

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 8 11:03:30 PST 2022


Quuxplusone updated this revision to Diff 413881.
Quuxplusone retitled this revision from "[libc++] Add a test for std::ssize's SFINAE. [WIP]" to "[libc++] Add a test for std::ssize's SFINAE".
Quuxplusone added a comment.

Try a .sh.cpp test. This might be ready for review, although I assume I'll have to UNSUPPORTED a few platforms depending on what CI says.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121154/new/

https://reviews.llvm.org/D121154

Files:
  libcxx/test/std/iterators/iterator.container/ssize.sfinae.sh.cpp


Index: libcxx/test/std/iterators/iterator.container/ssize.sfinae.sh.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/iterators/iterator.container/ssize.sfinae.sh.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+// UNSUPPORTED: libcpp-has-no-concepts
+
+// RUN: %{cxx} %{flags} %{compile_flags} -m32 -c %s
+
+// <iterator>
+
+// template <class T, ptrdiff_t N>
+//   constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept;
+//
+// Peter Dimov gives "clang -m32" as an example of a platform where the
+// use of ptrdiff_t, not size_t, has an observable SFINAE effect.
+
+#include <iterator>
+#include <climits>
+
+static_assert(sizeof(std::ptrdiff_t) == 4, "Run only on these platforms");
+static_assert(sizeof(std::size_t) == 4, "Run only on these platforms");
+static_assert(size_t(PTRDIFF_MAX) + 1 > size_t(PTRDIFF_MAX), "This should always be true");
+
+extern char forming_this_type_must_be_valid_on_this_platform[size_t(PTRDIFF_MAX) + 1];
+
+template<class T>
+concept HasSsize = requires (T&& t) {
+    std::ssize(t);
+};
+
+static_assert( HasSsize<char[size_t(PTRDIFF_MAX)]>);
+static_assert(!HasSsize<char[size_t(PTRDIFF_MAX) + 1]>);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121154.413881.patch
Type: text/x-patch
Size: 1594 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220308/4f2b903d/attachment.bin>


More information about the libcxx-commits mailing list