brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 1ca68b1 Raw
39 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 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_t18// instead of size_t in std::ssize has an observable SFINAE effect.19//20// REQUIRES: 32-bit-pointer21 22#include <iterator>23#include <climits>24#include <cstddef>25#include <cstdint>26 27// Test the test:28static_assert(sizeof(std::ptrdiff_t) == 4, "Run only on these platforms");29static_assert(sizeof(std::size_t) == 4, "Run only on these platforms");30static_assert(std::size_t(PTRDIFF_MAX) + 1 > std::size_t(PTRDIFF_MAX), "This should always be true");31extern char forming_this_type_must_be_valid_on_this_platform[std::size_t(PTRDIFF_MAX) + 1];32 33// The actual test:34template <class T>35concept HasSsize = requires(T&& t) { std::ssize(t); };36 37static_assert(HasSsize<char[std::size_t(PTRDIFF_MAX)]>);38static_assert(!HasSsize<char[std::size_t(PTRDIFF_MAX) + 1]>);39