bool.pass.cpp 986 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // UNSUPPORTED: c++98, c++03, c++11, c++14
  9. // <optional>
  10. // constexpr explicit optional<T>::operator bool() const noexcept;
  11. #include <optional>
  12. #include <type_traits>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. int main(int, char**)
  16. {
  17. using std::optional;
  18. {
  19. const optional<int> opt; ((void)opt);
  20. ASSERT_NOEXCEPT(bool(opt));
  21. static_assert(!std::is_convertible<optional<int>, bool>::value, "");
  22. }
  23. {
  24. constexpr optional<int> opt;
  25. static_assert(!opt, "");
  26. }
  27. {
  28. constexpr optional<int> opt(0);
  29. static_assert(opt, "");
  30. }
  31. return 0;
  32. }