diff --git a/libcxx/test/std/iterators/iterator.container/ssize.sfinae.sh.cpp b/libcxx/test/std/iterators/iterator.container/ssize.sfinae.sh.cpp new file mode 100644 --- /dev/null +++ b/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 + +// + +// template +// 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 +#include + +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 +concept HasSsize = requires (T&& t) { + std::ssize(t); +}; + +static_assert( HasSsize); +static_assert(!HasSsize);