]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/type_identity/requirements/typedefs.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / type_identity / requirements / typedefs.cc
CommitLineData
a945c346 1// Copyright (C) 2018-2024 Free Software Foundation, Inc.
ee896276
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8//
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
6d0b43f5 18// { dg-do compile { target c++20 } }
ee896276
JW
19
20#include <type_traits>
21
22template<typename T, typename = typename std::type_identity<T>::type>
23 struct test; // undefined
24
25template<typename T>
26 struct test<T, T> : std::true_type { };
27
28enum test_enum { };
29struct test_class { };
30struct incomplete_class;
31
32void test01()
33{
34 static_assert(test<float>::value, "");
35 static_assert(test<const unsigned int>::value, "");
36 static_assert(test<const unsigned int>::value, "");
37 static_assert(test<volatile unsigned int>::value, "");
38 static_assert(test<const volatile unsigned int>::value, "");
39 static_assert(test<const unsigned char>::value, "");
ee896276 40 static_assert(test<volatile wchar_t>::value, "" );
ee896276
JW
41
42 // Pointers
43 static_assert(test<void*>::value, "");
44 static_assert(test<long*>::value, "");
45 // References
46 static_assert(test<short&>::value, "");
47 static_assert(test<char&&>::value, "");
48 static_assert(test<int*&>::value, "");
49 // Arrays
50 static_assert(test<int[]>::value, "");
51 static_assert(test<int[2]>::value, "");
52 static_assert(test<int[2][3]>::value, "");
53 static_assert(test<int(*)[2]>::value, "");
54 static_assert(test<int(&)[2]>::value, "");
55
56 static_assert(test<test_enum>::value, "");
57 static_assert(test<test_class>::value, "");
58 static_assert(test<incomplete_class>::value, "");
59
60 // Functions
61 static_assert(test<void(*)()>::value, "");
62 static_assert(test<int(*)(int) noexcept>::value, "");
63 static_assert(test<void(&)()>::value, "");
64 static_assert(test<long(&)(long) noexcept>::value, "");
65 static_assert(test<void()>::value, "");
66 static_assert(test<int(int, int)>::value, "");
67 static_assert(test<void() noexcept>::value, "");
68 static_assert(test<int(int, int) noexcept>::value, "");
69
70 // Abominable function types
71 static_assert(test<void(int) const>::value, "");
72 static_assert(test<void(int) const volatile>::value, "");
73
74 // Pointers to members
75 static_assert(test<int incomplete_class::*>::value, "");
76 static_assert(test<void(incomplete_class::*)(int)>::value, "");
77 static_assert(test<void(incomplete_class::*)(int) noexcept>::value, "");
78 static_assert(test<void(incomplete_class::*)() const>::value, "");
79 static_assert(test<void(incomplete_class::*)() &>::value, "");
80 static_assert(test<void(incomplete_class::*)() &&>::value, "");
81 static_assert(test<void(incomplete_class::*)() volatile &&>::value, "");
82
83#ifndef __STRICT_ANSI__
84 // GNU Extensions.
29a9de9b 85#ifdef __SIZEOF_INT128__
ee896276
JW
86 static_assert(test<unsigned __int128>::value, "");
87 static_assert(test<unsigned __int128>::value, "");
88#endif
89#endif
90}