1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// <iterator>
12
13// template <class T, ptrdiff_t N>
14// constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept;
15//
16// This test checks that the library implements LWG3207 as not-a-defect.
17// `clang -m32` is an example of a configuration where using ptrdiff_t
18// instead of size_t in std::ssize has an observable SFINAE effect.
19//
20// REQUIRES: 32-bit-pointer
21
22#include <iterator>
23#include <climits>
24#include <cstddef>
25
26// Test the test:
27static_assert(sizeof(std::ptrdiff_t) == 4, "Run only on these platforms");
28static_assert(sizeof(std::size_t) == 4, "Run only on these platforms");
29static_assert(std::size_t(PTRDIFF_MAX) + 1 > std::size_t(PTRDIFF_MAX), "This should always be true");
30extern char forming_this_type_must_be_valid_on_this_platform[std::size_t(PTRDIFF_MAX) + 1];
31
32// The actual test:
33template <class T>
34concept HasSsize = requires(T&& t) { std::ssize(t); };
35
36static_assert(HasSsize<char[std::size_t(PTRDIFF_MAX)]>);
37static_assert(!HasSsize<char[std::size_t(PTRDIFF_MAX) + 1]>);
38

source code of libcxx/test/std/iterators/iterator.container/ssize.LWG3207.compile.pass.cpp