xref: /llvm-project/libcxx/test/std/iterators/iterator.container/ssize.LWG3207.compile.pass.cpp (revision 3df1a64ebad8f31231ba05cf6ff43a985fea9235)
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:
27 static_assert(sizeof(std::ptrdiff_t) == 4, "Run only on these platforms");
28 static_assert(sizeof(std::size_t) == 4, "Run only on these platforms");
29 static_assert(std::size_t(PTRDIFF_MAX) + 1 > std::size_t(PTRDIFF_MAX), "This should always be true");
30 extern char forming_this_type_must_be_valid_on_this_platform[std::size_t(PTRDIFF_MAX) + 1];
31 
32 // The actual test:
33 template <class T>
34 concept HasSsize = requires(T&& t) { std::ssize(t); };
35 
36 static_assert(HasSsize<char[std::size_t(PTRDIFF_MAX)]>);
37 static_assert(!HasSsize<char[std::size_t(PTRDIFF_MAX) + 1]>);
38