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