| 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 |
// UNSUPPORTED: clang-17 |
| 11 |
|
| 12 |
// <utility> |
| 13 |
|
| 14 |
// LWG-3382 NTTP for pair and array: |
| 15 |
// pair<T, U> is a structural type ([temp.param]) if T and U are both structural types. |
| 16 |
|
| 17 |
#include <utility> |
| 18 |
|
| 19 |
#include <functional> |
| 20 |
#include <string> |
| 21 |
|
| 22 |
struct LiteralBase {}; |
| 23 |
struct LiteralNSDM {}; |
| 24 |
|
| 25 |
struct LiteralType : LiteralBase { |
| 26 |
LiteralNSDM nsdm; |
| 27 |
}; |
| 28 |
|
| 29 |
struct NotALiteral { |
| 30 |
NotALiteral() {} |
| 31 |
}; |
| 32 |
|
| 33 |
int i; |
| 34 |
NotALiteral not_a_literal; |
| 35 |
|
| 36 |
namespace test_full_type { |
| 37 |
template <class T, class U, std::pair<T, U> P> |
| 38 |
struct test {}; |
| 39 |
|
| 40 |
using A = test<int, int, std::pair{0, 1}>; |
| 41 |
using B = test<int&, int&, std::make_pair(std::ref(i), std::ref(i))>; |
| 42 |
using C = test<const int&, const int&, std::make_pair(std::cref(i), std::cref(i))>; |
| 43 |
using D = test<LiteralType, LiteralType, std::pair<LiteralType, LiteralType>{}>; |
| 44 |
using E = test<int*, int*, std::pair<int*, int*>{&i, &i}>; |
| 45 |
using F = test<NotALiteral&, NotALiteral&, std::make_pair(std::ref(not_a_literal), std::ref(not_a_literal))>; |
| 46 |
|
| 47 |
using G = test<int&&, int&&, std::pair<int&&, int&&>{std::move(i), std::move(i)}>; |
| 48 |
// expected-error@*:* {{type 'std::pair<int &&, int &&>' of non-type template parameter is not a structural type}} |
| 49 |
|
| 50 |
using H = test<NotALiteral, NotALiteral, std::pair<NotALiteral, NotALiteral>{}>; |
| 51 |
// expected-error@*:* {{non-type template parameter has non-literal type 'std::pair<NotALiteral, NotALiteral>'}} |
| 52 |
|
| 53 |
using I = test<std::string, std::string, std::pair<std::string, std::string>{}>; |
| 54 |
// expected-error-re@*:* {{type 'std::pair<{{(std::)?}}string, {{(std::)?}}string>' {{(\(aka 'pair<basic_string<char>, basic_string<char>>'\) )?}}of non-type template parameter is not a structural type}} |
| 55 |
} // namespace test_full_type |
| 56 |
|
| 57 |
namespace test_ctad { |
| 58 |
template <std::pair P> |
| 59 |
struct test {}; |
| 60 |
|
| 61 |
using A = test<std::pair{2, 3}>; |
| 62 |
using B = test<std::make_pair(std::ref(i), std::ref(i))>; |
| 63 |
using C = test<std::make_pair(std::cref(i), std::cref(i))>; |
| 64 |
using D = test<std::pair<LiteralType, LiteralType>{}>; |
| 65 |
using E = test<std::pair<int*, int*>{&i, &i}>; |
| 66 |
using F = test<std::make_pair(std::ref(not_a_literal), std::ref(not_a_literal))>; |
| 67 |
|
| 68 |
using G = test<std::pair<int&&, int&&>{std::move(i), std::move(i)}>; |
| 69 |
// expected-error@-1 {{type 'std::pair<int &&, int &&>' of non-type template parameter is not a structural type}} |
| 70 |
|
| 71 |
using H = test<std::pair<NotALiteral, NotALiteral>{}>; |
| 72 |
// expected-error@-1 {{non-type template parameter has non-literal type 'std::pair<NotALiteral, NotALiteral>'}} |
| 73 |
|
| 74 |
using I = test<std::pair<std::string, std::string>{}>; |
| 75 |
// expected-error@-1 {{type 'std::pair<string, string>' (aka 'std::pair<std::string, std::string>') of non-type template parameter is not a structural type}} |
| 76 |
} // namespace test_ctad |
| 77 |
|
| 78 |
namespace test_auto { |
| 79 |
template <auto P> |
| 80 |
struct test {}; |
| 81 |
|
| 82 |
using A = test<std::pair{4, 5}>; |
| 83 |
using B = test<std::make_pair(std::ref(i), std::ref(i))>; |
| 84 |
using C = test<std::make_pair(std::cref(i), std::cref(i))>; |
| 85 |
using D = test<std::pair<LiteralType, LiteralType>{}>; |
| 86 |
using E = test<std::pair<int*, int*>{&i, &i}>; |
| 87 |
using F = test<std::make_pair(std::ref(not_a_literal), std::ref(not_a_literal))>; |
| 88 |
|
| 89 |
using G = test<std::pair<int&&, int&&>{std::move(i), std::move(i)}>; |
| 90 |
// expected-error@-1 {{type 'std::pair<int &&, int &&>' of non-type template parameter is not a structural type}} |
| 91 |
|
| 92 |
using H = test<std::pair<NotALiteral, NotALiteral>{}>; |
| 93 |
// expected-error@-1 {{non-type template parameter has non-literal type 'std::pair<NotALiteral, NotALiteral>'}} |
| 94 |
|
| 95 |
using I = test<std::pair<std::string, std::string>{}>; |
| 96 |
// expected-error@-1 {{type 'std::pair<std::string, std::string>' (aka 'pair<basic_string<char>, basic_string<char>>') of non-type template parameter is not a structural type}} |
| 97 |
} // namespace test_auto |