xref: /llvm-project/libcxx/test/std/diagnostics/syserr/syserr.errcode/syserr.errcode.observers/bool.pass.cpp (revision 317e92a3e82f88f111e04132195d9daa6b97f1ab)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <system_error>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // class error_code
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // explicit operator bool() const;
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <system_error>
165a83710eSEric Fiselier #include <cassert>
17*317e92a3SArthur O'Dwyer #include <string>
18*317e92a3SArthur O'Dwyer #include <type_traits>
195a83710eSEric Fiselier 
207fc6a556SMarshall Clow #include "test_macros.h"
217fc6a556SMarshall Clow 
main(int,char **)222df59c50SJF Bastien int main(int, char**)
235a83710eSEric Fiselier {
24*317e92a3SArthur O'Dwyer     static_assert(std::is_constructible<bool, std::error_code>::value, "");
25*317e92a3SArthur O'Dwyer     static_assert(!std::is_convertible<std::error_code, bool>::value, "");
26*317e92a3SArthur O'Dwyer 
275a83710eSEric Fiselier     {
285a83710eSEric Fiselier         const std::error_code ec(6, std::generic_category());
295a83710eSEric Fiselier         assert(static_cast<bool>(ec));
305a83710eSEric Fiselier     }
315a83710eSEric Fiselier     {
325a83710eSEric Fiselier         const std::error_code ec(0, std::generic_category());
335a83710eSEric Fiselier         assert(!static_cast<bool>(ec));
345a83710eSEric Fiselier     }
352df59c50SJF Bastien 
362df59c50SJF Bastien   return 0;
375a83710eSEric Fiselier }
38