diff options
Diffstat (limited to 'libcxx/test/std/containers/sequences/array/array.overview')
| -rw-r--r-- | libcxx/test/std/containers/sequences/array/array.overview/nttp.equivalence.compile.pass.cpp | 70 | ||||
| -rw-r--r-- | libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp | 81 |
2 files changed, 151 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/sequences/array/array.overview/nttp.equivalence.compile.pass.cpp b/libcxx/test/std/containers/sequences/array/array.overview/nttp.equivalence.compile.pass.cpp new file mode 100644 index 000000000000..29e10fd40bd3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.overview/nttp.equivalence.compile.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <array> + +// LWG-3382 NTTP for pair and array: +// Two values a1 and a2 of type array<T, N> are template-argument-equivalent if and only if each pair of corresponding +// elements in a1 and a2 are template-argument-equivalent. + +#include <array> + +#include <type_traits> + +namespace test_full_type { +template <class T, std::size_t S, std::array<T, S> A> +struct test : std::false_type {}; + +template <> +struct test<int, 3, std::array<int, 3>{1, 2, 3}> : std::true_type {}; + +static_assert(!test<int*, 4, std::array<int*, 4>{}>::value); +static_assert(!test<int*, 3, std::array<int*, 3>{}>::value); +static_assert(!test<int, 3, std::array<int, 3>{}>::value); +static_assert(!test<int, 3, std::array<int, 3>{1}>::value); +static_assert(!test<int, 3, std::array<int, 3>{1, 2}>::value); +static_assert(!test<long, 3, std::array<long, 3>{1, 2, 3}>::value); +static_assert(!test<unsigned int, 3, std::array<unsigned int, 3>{1, 2, 3}>::value); +static_assert(test<int, 3, std::array<int, 3>{1, 2, 3}>::value); +} // namespace test_full_type + +namespace test_ctad { +template <std::array A> +struct test : std::false_type {}; + +template <> +struct test<std::array<int, 3>{4, 5, 6}> : std::true_type {}; + +static_assert(!test<std::array<int*, 4>{}>::value); +static_assert(!test<std::array<int*, 3>{}>::value); +static_assert(!test<std::array<int, 3>{}>::value); +static_assert(!test<std::array<int, 3>{4}>::value); +static_assert(!test<std::array<int, 3>{4, 5}>::value); +static_assert(!test<std::array<long, 3>{4, 5, 6}>::value); +static_assert(!test<std::array<unsigned int, 3>{4, 5, 6}>::value); +static_assert(test<std::array<int, 3>{4, 5, 6}>::value); +} // namespace test_ctad + +namespace test_auto { +template <auto A> +struct test : std::false_type {}; + +template <> +struct test<std::array<int, 3>{7, 8, 9}> : std::true_type {}; + +static_assert(!test<std::array<int*, 4>{}>::value); +static_assert(!test<std::array<int*, 3>{}>::value); +static_assert(!test<std::array<int, 3>{}>::value); +static_assert(!test<std::array<int, 3>{7}>::value); +static_assert(!test<std::array<int, 3>{7, 8}>::value); +static_assert(!test<std::array<long, 3>{7, 8, 9}>::value); +static_assert(!test<std::array<unsigned int, 3>{7, 8, 9}>::value); +static_assert(test<std::array<int, 3>{7, 8, 9}>::value); +} // namespace test_auto diff --git a/libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp b/libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp new file mode 100644 index 000000000000..3eb8e2596f85 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// <array> + +// LWG-3382 NTTP for pair and array: +// array<T, N> is a structural type ([temp.param]) if T is a structural type. + +#include <array> + +#include <cstddef> +#include <string> + +struct LiteralBase {}; +struct LiteralNSDM {}; + +struct LiteralType : LiteralBase { + LiteralNSDM nsdm; +}; + +struct NotALiteral { + NotALiteral() {} +}; + +int i; +NotALiteral not_a_literal; + +namespace test_full_type { +template <class T, std::size_t S, std::array<T, S> A> +struct test {}; + +using A = test<int, 2, std::array{2, 3}>; +using B = test<LiteralType, 0, std::array<LiteralType, 0>{}>; +using C = test<int*, 1, std::array<int*, 1>{&i}>; +using D = test<NotALiteral*, 1, std::array<NotALiteral*, 1>{¬_a_literal}>; + +using E = test<NotALiteral, 1, std::array<NotALiteral, 1>{}>; +// expected-error-re@*:* {{non-type template parameter has non-literal type 'std::array<NotALiteral, 1U{{L{0,2}.*}}>'}} + +using F = test<std::string, 2, std::array<std::string, 2>{}>; +// expected-error-re@*:* {{type 'std::array<{{(std::)?}}string, 2U{{L{0,2}.*}}>' {{(\(aka 'array<basic_string<char>, 2UL{0,2}>'\) )?}}of non-type template parameter is not a structural type}} +} // namespace test_full_type + +namespace test_ctad { +template <std::array A> +struct test {}; + +using A = test<std::array{2, 3}>; +using B = test<std::array<LiteralType, 0>{}>; +using C = test<std::array<int*, 1>{&i}>; +using D = test<std::array<NotALiteral*, 1>{¬_a_literal}>; + +using E = test<std::array<NotALiteral, 1>{}>; +// expected-error@-1 {{non-type template parameter has non-literal type 'std::array<NotALiteral, 1>'}} + +using F = test<std::array<std::string, 2>{}>; +// expected-error@-1 {{type 'std::array<string, 2>' (aka 'std::array<std::string, 2>') of non-type template parameter is not a structural type}} +} // namespace test_ctad + +namespace test_auto { +template <auto A> +struct test {}; + +using A = test<std::array{2, 3}>; +using B = test<std::array<LiteralType, 0>{}>; +using C = test<std::array<int*, 1>{&i}>; +using D = test<std::array<NotALiteral*, 1>{¬_a_literal}>; + +using E = test<std::array<NotALiteral, 1>{}>; +// expected-error@-1 {{non-type template parameter has non-literal type 'std::array<NotALiteral, 1>'}} + +using F = test<std::array<std::string, 2>{}>; +// expected-error@-1 {{type 'std::array<std::string, 2>' (aka 'array<basic_string<char>, 2>') of non-type template parameter is not a structural type}} +} // namespace test_auto |
