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// <array>
12
13// LWG-3382 NTTP for pair and array:
14// array<T, N> is a structural type ([temp.param]) if T is a structural type.
15
16#include <array>
17
18#include <cstddef>
19#include <string>
20
21struct LiteralBase {};
22struct LiteralNSDM {};
23
24struct LiteralType : LiteralBase {
25 LiteralNSDM nsdm;
26};
27
28struct NotALiteral {
29 NotALiteral() {}
30};
31
32int i;
33NotALiteral not_a_literal;
34
35namespace test_full_type {
36template <class T, std::size_t S, std::array<T, S> A>
37struct test {};
38
39using A = test<int, 2, std::array{2, 3}>;
40using B = test<LiteralType, 0, std::array<LiteralType, 0>{}>;
41using C = test<int*, 1, std::array<int*, 1>{&i}>;
42using D = test<NotALiteral*, 1, std::array<NotALiteral*, 1>{&not_a_literal}>;
43
44using E = test<NotALiteral, 1, std::array<NotALiteral, 1>{}>;
45// expected-error-re@*:* {{non-type template parameter has non-literal type 'std::array<NotALiteral, 1U{{L{0,2}.*}}>'}}
46
47using F = test<std::string, 2, std::array<std::string, 2>{}>;
48// 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}}
49} // namespace test_full_type
50
51namespace test_ctad {
52template <std::array A>
53struct test {};
54
55using A = test<std::array{2, 3}>;
56using B = test<std::array<LiteralType, 0>{}>;
57using C = test<std::array<int*, 1>{&i}>;
58using D = test<std::array<NotALiteral*, 1>{&not_a_literal}>;
59
60using E = test<std::array<NotALiteral, 1>{}>;
61// expected-error@-1 {{non-type template parameter has non-literal type 'std::array<NotALiteral, 1>'}}
62
63using F = test<std::array<std::string, 2>{}>;
64// expected-error-re@-1 {{type 'std::array<{{(std::)?}}string, 2>'{{( \(aka 'std::array<std::string, 2>'\))?}} of non-type template parameter is not a structural type}}
65} // namespace test_ctad
66
67namespace test_auto {
68template <auto A>
69struct test {};
70
71using A = test<std::array{2, 3}>;
72using B = test<std::array<LiteralType, 0>{}>;
73using C = test<std::array<int*, 1>{&i}>;
74using D = test<std::array<NotALiteral*, 1>{&not_a_literal}>;
75
76using E = test<std::array<NotALiteral, 1>{}>;
77// expected-error@-1 {{non-type template parameter has non-literal type 'std::array<NotALiteral, 1>'}}
78
79using F = test<std::array<std::string, 2>{}>;
80// 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}}
81} // namespace test_auto
82

source code of libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp