xref: /llvm-project/libcxx/test/std/diagnostics/syserr/is_error_condition_enum.pass.cpp (revision 93df7b9f75af6b4282565e6e98bb306590375820)
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
10 
11 // <system_error>
12 
13 // template <class T> constexpr bool is_error_condition_enum_v;
14 
15 #include <system_error>
16 #include <type_traits>
17 #include "test_macros.h"
18 
19 template <bool Expected, class T>
20 void
21 test()
22 {
23     static_assert((std::is_error_condition_enum<T>::value == Expected), "");
24 #if TEST_STD_VER > 14
25     static_assert((std::is_error_condition_enum_v<T>        == Expected), "");
26     ASSERT_SAME_TYPE(decltype(std::is_error_condition_enum_v<T>), const bool);
27 #endif
28 }
29 
30 class A {
31     A();
32     operator std::error_condition () const { return std::error_condition(); }
33 };
34 
35 // Specialize the template for my class
36 namespace std
37 {
38   template <>
39   struct is_error_condition_enum<A> : public std::true_type {};
40 }
41 
42 
43 int main(int, char**)
44 {
45     test<false, void>();
46     test<false, int>();
47     test<false, std::nullptr_t>();
48     test<false, std::string>();
49 
50     test<true, A>();
51 
52   return 0;
53 }
54