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// type_traits
10
11// is_function
12
13#include <type_traits>
14#include <cstddef> // for std::nullptr_t
15
16#include "test_macros.h"
17
18// NOTE: On Windows the function `test_is_function<void()>` and
19// `test_is_function<void() noexcept> has the same mangled despite being
20// a distinct instantiation. This causes Clang to emit an error. However
21// structs do not have this problem.
22
23template <class T>
24struct test_is_function {
25 static_assert( std::is_function<T>::value, "");
26 static_assert( std::is_function<const T>::value, "");
27 static_assert( std::is_function<volatile T>::value, "");
28 static_assert( std::is_function<const volatile T>::value, "");
29#if TEST_STD_VER > 14
30 static_assert( std::is_function_v<T>, "");
31 static_assert( std::is_function_v<const T>, "");
32 static_assert( std::is_function_v<volatile T>, "");
33 static_assert( std::is_function_v<const volatile T>, "");
34#endif
35};
36
37template <class T>
38struct test_is_not_function {
39 static_assert(!std::is_function<T>::value, "");
40 static_assert(!std::is_function<const T>::value, "");
41 static_assert(!std::is_function<volatile T>::value, "");
42 static_assert(!std::is_function<const volatile T>::value, "");
43#if TEST_STD_VER > 14
44 static_assert(!std::is_function_v<T>, "");
45 static_assert(!std::is_function_v<const T>, "");
46 static_assert(!std::is_function_v<volatile T>, "");
47 static_assert(!std::is_function_v<const volatile T>, "");
48#endif
49};
50
51class Empty
52{
53};
54
55class NotEmpty
56{
57 virtual ~NotEmpty();
58};
59
60union Union {};
61
62struct bit_zero
63{
64 int : 0;
65};
66
67class Abstract
68{
69 virtual ~Abstract() = 0;
70};
71
72enum Enum {zero, one};
73struct incomplete_type;
74
75typedef void (*FunctionPtr)();
76
77int main(int, char**)
78{
79 test_is_function<void(void)>();
80 test_is_function<int(int)>();
81 test_is_function<int(int, double)>();
82 test_is_function<int(Abstract *)>();
83 test_is_function<void(...)>();
84
85 test_is_not_function<std::nullptr_t>();
86 test_is_not_function<void>();
87 test_is_not_function<int>();
88 test_is_not_function<int&>();
89 test_is_not_function<int&&>();
90 test_is_not_function<int*>();
91 test_is_not_function<double>();
92 test_is_not_function<char[3]>();
93 test_is_not_function<char[]>();
94 test_is_not_function<Union>();
95 test_is_not_function<Enum>();
96 test_is_not_function<FunctionPtr>(); // function pointer is not a function
97 test_is_not_function<Empty>();
98 test_is_not_function<bit_zero>();
99 test_is_not_function<NotEmpty>();
100 test_is_not_function<Abstract>();
101 test_is_not_function<Abstract*>();
102 test_is_not_function<incomplete_type>();
103
104#if TEST_STD_VER >= 11
105 test_is_function<void() noexcept>();
106 test_is_function<void() const && noexcept>();
107#endif
108
109 return 0;
110}
111

source code of libcxx/test/std/utilities/meta/meta.unary/meta.unary.cat/is_function.pass.cpp