xref: /llvm-project/libcxx/test/std/diagnostics/syserr/is_error_condition_enum.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
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++98, 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 #endif
27 }
28 
29 class A {
30     A();
31     operator std::error_condition () const { return std::error_condition(); }
32 };
33 
34 // Specialize the template for my class
35 namespace std
36 {
37   template <>
38   struct is_error_condition_enum<A> : public std::true_type {};
39 }
40 
41 
42 int main(int, char**)
43 {
44     test<false, void>();
45     test<false, int>();
46     test<false, std::nullptr_t>();
47     test<false, std::string>();
48 
49     test<true, A>();
50 
51   return 0;
52 }
53