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

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 7 13:05:09 PST 2022


Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, libc++.
Quuxplusone added a project: libc++.
Herald added a project: All.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

Inspired by https://reviews.llvm.org/D120684#inline-1157644 and subsequent LWG discussion.
See https://cplusplus.github.io/LWG/issue3207 for not-enough-background. :)

Wondering how to restrict this to run on just these weird 32-bit-ptrdiff_t/64-bit-pointer platforms, without running the risk of quietly nerfing the test forever and never noticing.

@ldionne, I wonder if there's a way to get buildkite to alert us about test files that have been skipped in **all** jobs. That would be generally useful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121154

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


Index: libcxx/test/std/iterators/iterator.container/ssize.sfinae.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/iterators/iterator.container/ssize.sfinae.compile.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <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 && sizeof(std::size_t) == 8), "Run only on these platforms");
+
+template<class T>
+concept HasSsize = requires (T&& t) {
+    std::ssize(t);
+};
+
+//static_assert( HasSsize<char[size_t(INT_MAX) + 0]>);
+//static_assert(!HasSsize<char[size_t(INT_MAX) + 1]>);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121154.413607.patch
Type: text/x-patch
Size: 1334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220307/2198f6f7/attachment.bin>


More information about the libcxx-commits mailing list